-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor WebAssembly -dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server #48249
Comments
Thanks for contacting us. |
It might be that a type converter is being trimmed. FYI @eerhardt |
Thanks. We are using NET5 not NET core 3.1 |
we are already used false . but that did not fix the issue. Thanks |
@rogerge88 - can you provide a link to a project (or a .zip) that reproduces the issue? |
@eerhardt OK and I will upload it. Thanks |
@eerhardt Zip file is bigger than 10 MB(about 50 MB after zip) , how to upload it?Thanks |
Can you delete the |
Struct.Issue.zip |
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsDescribe the bug"we are not using blazer server .We are using Blazor WebAssembly . and the issue that the dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server." Struct data(Color : IEquatable) cannot "deserialize" when deployed the Blazor to IIS server. Error message...... To ReproduceExceptions (if any)Further technical details
|
Tagging subscribers to this area: @safern, @tarekgh Issue DetailsDescribe the bug"we are not using blazer server .We are using Blazor WebAssembly . and the issue that the dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server." Struct data(Color : IEquatable) cannot "deserialize" when deployed the Blazor to IIS server. Error message...... To ReproduceExceptions (if any)Further technical details
|
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescribe the bug"we are not using blazer server .We are using Blazor WebAssembly . and the issue that the dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server." Struct data(Color : IEquatable) cannot "deserialize" when deployed the Blazor to IIS server. Error message...... To ReproduceExceptions (if any)Further technical details
|
@eerhardt did you tag this as |
Moving to @rogerge88 - thanks for the repro project! It really helped speed up the investigation here. I am able to reproduce this issue in a simple console app. using System;
using System.Collections.Generic;
using System.Drawing;
using Newtonsoft.Json;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var data = @"{""name"":""Test"",""sizes"":[{""id"":0,""tileSize"":""256, 256""}],""colors"":[{""id"":0,""color"":""51, 136, 255""}]}";
var s = JsonConvert.DeserializeObject<Shape>(data);
Console.WriteLine(s.Sizes[0].TileSize);
}
}
public class Shape
{
public string Name { get; set; }
public List<Sizelayer> Sizes { get; set; }
public List<ColorLayer> Colors { get; set; }
}
public class Sizelayer
{
public int Id { get; set; }
public Size TileSize { get; set; } = new Size(256, 256);
}
public class ColorLayer
{
public int Id { get; set; }
public Color Color { get; set; } = Color.FromArgb(0x33, 0x88, 0xFF);
}
}
The ProblemThe reason the exception is occurring is because the runtime/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs Lines 13 to 15 in c636bbd
However, it isn't. And the reason it isn't is because of the string in that attribute is pointing to I think the simple fix here is to change the above line to
So we don't have to "hop" through |
IIRC the reason why the TypeConverter's used the full framework assembly name was due to it being serializable and to avoid problems on serialization in between frameworks. Is that something we're still concerned about? |
@rogerge88 - to workaround this for now, to unblock yourself:
<linker>
<assembly fullname="System.ComponentModel.TypeConverter">
<!-- Workaround for https://github.com/dotnet/runtime/issues/48249 -->
<type fullname="System.Drawing.SizeConverter">
<method name=".ctor" />
</type>
<type fullname="System.Drawing.ColorConverter">
<method name=".ctor" />
</type>
</assembly>
</linker>
<ItemGroup>
<TrimmerRootDescriptor Include="ILLink.Descriptors.xml" />
</ItemGroup> NOTE: as you can tell from the .xml file, the same bug occurs for the runtime/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs Lines 14 to 17 in c636bbd
|
I'm not fully understanding this. This is a string in the
Given https://github.com/dotnet/designs/blob/main/accepted/2020/better-obsoletion/binaryformatter-obsoletion.md, we will soon not be concerned about it. |
Using the latest One thing that was still confusing me is how does the The answer is this bit of code in the Lines 482 to 521 in 8a52f1e
This will trim off the assembly portion of the string and just call However, this isn't a great solution IMO. We could hit this same problem anywhere else that tries using these strings in a post-trimmed application. If they didn't have the same kind of fallback code, the application will be broken. |
If the string literal was without assembly name, trimmer would figure it out, the problem is pointing to effectively non-existent assembly name - which with this could in theory happen. |
Thank you all. We will study it and apply it in our application for testing. Thanks. |
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @tannergooding, @sbomer Issue DetailsDescribe the bug"we are not using blazer server .We are using Blazor WebAssembly . and the issue that the dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server." Struct data(Color : IEquatable) cannot "deserialize" when deployed the Blazor to IIS server. Error message...... To ReproduceExceptions (if any)Further technical details
|
@eerhardt By following your "to workaround this for now, to unblock yourself..." and we have successfully resolved this issue. Great! Thank you all for the helps and suggestions. We understand that this bug will be fixed in the next release. thanks. |
Reopening, as we need to fix the product to support this out of the box. |
@eerhardt Thank you for helps and we had it to work based on your "to workaround this for now, to unblock yourself 1 & 2..." . However, after implemented the fix you provided the Devop throw below error during build: |
It sounds like the linker is throwing an exception for some reason. Is that all the error logs you are getting? It should be printing out what exception occurred, which will point you to what is wrong. I'm just guessing, but you might have the wrong file name in your .csproj. Make sure you are pointing to the right file in <ItemGroup>
<TrimmerRootDescriptor Include="ILLink.Descriptors.xml" />
</ItemGroup> And make sure the |
@eerhardt The issues has been fixed and we can get the correct result coming from the server. Thank you! |
@eerhardt and all, The "same issue happened when getting the enum attribute. it works locally but not after deployment" . The following is the code for you to duplicate the issue. Thanks. public static string GetEnumCategory<T>(this T enumValue)
where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
return null;
var enumCategory = enumValue.ToString();
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
if (fieldInfo != null)
{
var attrs = fieldInfo.GetCustomAttributes(typeof(CategoryAttribute), false);
if (attrs != null && attrs.Length > 0)
{
enumCategory = ((CategoryAttribute)attrs[0]).Category;
}
}
return enumCategory;
}
public enum AnEnum
{
[Description("Somthing"), Category("SomthingCat")]
Somthing = 52,
}
category local result = "category", after deployment result = "PropertyCategorycategory" Please let me know if you need more info about this issue. Thanks! |
-----Could you please give us some suggestion for above the new related issue? Thanks! |
@rogerge88 - This is a new issue. In the future, please open a new issue when you have a new scenario. I've opened #49554 for this new issue. To work around it until we can get a fix out, you can set: <PropertyGroup>
<UseSystemResourceKeys>false</UseSystemResourceKeys>
</PropertyGroup> in your .csproj. |
This may be fixed by the work we've done for facades. Assigning to myself to re-test. |
This is now fixed with the latest bits. Closing. |
Describe the bug
"we are not using blazer server .We are using Blazor WebAssembly . and the issue that the dieselization is working in the local code but it does not work when we deployed the Blazor to IIS server."
Struct data(Color : IEquatable) cannot "deserialize" when deployed the Blazor to IIS server.
It worked fine working in the local code.
Error message......
Newtonsoft.Json.JsonSerializationException: Error converting value "12, 12" to type
'System.Nullable`1[System.Drawing.Size]'. Path 'mapLayers[0].marker.icon.size', line 1, position 1272.
---> System.ArgumentException: Could not cast or convert from System.String to System.Drawing.Size.
at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
Exception_EndOfInnerExceptionStack
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
To Reproduce
Exceptions (if any)
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: