Skip to content
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

Closed
rogerge88 opened this issue Feb 11, 2021 · 32 comments
Assignees
Labels
area-System.Drawing bug linkable-framework Issues associated with delivering a linker friendly framework
Milestone

Comments

@rogerge88
Copy link

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

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
Can you try to disable linking and see whether that will resolve the issue: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/configure-linker?view=aspnetcore-3.1#control-linking-with-an-msbuild-property

@pranavkm
Copy link
Contributor

It might be that a type converter is being trimmed. FYI @eerhardt

@rogerge88
Copy link
Author

rogerge88 commented Feb 11, 2021

Thanks. We are using NET5 not NET core 3.1
IDE: VS 2019

@rogerge88
Copy link
Author

we are already used false . but that did not fix the issue. Thanks

@eerhardt
Copy link
Member

eerhardt commented Feb 11, 2021

@rogerge88 - can you provide a link to a project (or a .zip) that reproduces the issue?

@rogerge88
Copy link
Author

@eerhardt OK and I will upload it. Thanks

@rogerge88
Copy link
Author

rogerge88 commented Feb 11, 2021

@eerhardt Zip file is bigger than 10 MB(about 50 MB after zip) , how to upload it?Thanks

@eerhardt
Copy link
Member

Can you delete the bin and obj folders before zipping?

@rogerge88
Copy link
Author

Struct.Issue.zip
@eerhardt Thank you and the zip file has been uploaded. Please let me know if you need more data.Thanks

@eerhardt eerhardt transferred this issue from dotnet/aspnetcore Feb 12, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Feb 12, 2021
@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

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

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: rogerge88
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to this area: @safern, @tarekgh
See info in area-owners.md if you want to be subscribed.

Issue Details

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

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: rogerge88
Assignees: -
Labels:

area-System.Drawing, untriaged

Milestone: -

@tarekgh tarekgh added the arch-wasm WebAssembly architecture label Feb 12, 2021
@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

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

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: rogerge88
Assignees: -
Labels:

arch-wasm, area-System.Drawing, untriaged

Milestone: -

@tarekgh
Copy link
Member

tarekgh commented Feb 12, 2021

@eerhardt did you tag this as System.Drawing because it is related to the Color type?

@eerhardt
Copy link
Member

Moving to dotnet/runtime since the problem lies here.

@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);
    }
}

dotnet publish -p:PublishTrimmed=true -p:TrimMode=link -r win-x64 that application and try to run it, and you get:

Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value "256, 256" to type 'System.Drawing.Size'. Path 'sizes[0].tileSize', line 1, position 53.
 ---> 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)

The Problem

The reason the exception is occurring is because the SizeConverter type is being trimmed unintentionally. The Type should be preserved because of the following line:

[TypeConverter("System.Drawing.SizeConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public struct Size : IEquatable<Size>
{

However, it isn't. And the reason it isn't is because of the string in that attribute is pointing to System.Drawing. There is a bug in the mono/linker where it has issues bringing in unreferenced assemblies into the graph (I think it is dotnet/linker#1164).

I think the simple fix here is to change the above line to

[TypeConverter("System.Drawing.SizeConverter, System.ComponentModel.TypeConverter")] 

So we don't have to "hop" through System.Drawing just to go where the type really lives. I think this is safe since System.Drawing.Primitives and System.ComponentModel.TypeConverter are both inbox and don't ship in any OOB packages.

cc @vitek-karas @ericstj

@eerhardt eerhardt removed the arch-wasm WebAssembly architecture label Feb 12, 2021
@tarekgh tarekgh added bug and removed untriaged New issue has not been triaged by the area owner labels Feb 12, 2021
@tarekgh tarekgh added this to the 6.0.0 milestone Feb 12, 2021
@safern
Copy link
Member

safern commented Feb 12, 2021

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?

@eerhardt
Copy link
Member

@rogerge88 - to workaround this for now, to unblock yourself:

  1. Add a new file to Struct.Issue.Client project named ILLink.Descriptors.xml with the following contents:
<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>
  1. Add the following entry to the Struct.Issue.Client.csproj
  <ItemGroup>
    <TrimmerRootDescriptor Include="ILLink.Descriptors.xml" />
  </ItemGroup>

NOTE: as you can tell from the .xml file, the same bug occurs for the ColorConverter:

[TypeConverter("System.Drawing.ColorConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public readonly struct Color : IEquatable<Color>
{

@eerhardt
Copy link
Member

was due to it being serializable

I'm not fully understanding this. This is a string in the TypeConverterAttribute, how does serialization come into play?

to avoid problems on serialization in between frameworks. Is that something we're still concerned about?

Given https://github.com/dotnet/designs/blob/main/accepted/2020/better-obsoletion/binaryformatter-obsoletion.md, we will soon not be concerned about it.

@eerhardt
Copy link
Member

Using the latest mono/linker build to trim the application will correctly preserve the SizeConverter and ColorConverter classes. So it appears that the piece of dotnet/linker#1164 that was blocking this scenario from working has been resolved in the latest bits.

One thing that was still confusing me is how does the TypeDescriptor.GetConverter(typeof(Size)) know how to find the converter named "System.Drawing.SizeConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" in a trimmed application? Note that the System.Drawing facade is trimmed away by the linker. But this string still remains in the IL even after trimming.

The answer is this bit of code in the System.ComponentModel.TypeConverter assembly:

/// <summary>
/// Retrieves a type from a name. The Assembly of the type
/// that this PropertyDescriptor came from is first checked,
/// then a global Type.GetType is performed.
/// </summary>
private Type GetTypeFromName(string typeName)
{
if (string.IsNullOrEmpty(typeName))
{
return null;
}
int commaIndex = typeName.IndexOf(',');
Type t = null;
if (commaIndex == -1)
{
t = _type.Assembly.GetType(typeName);
}
if (t == null)
{
t = Type.GetType(typeName);
}
if (t == null && commaIndex != -1)
{
// At design time, it's possible for us to reuse
// an assembly but add new types. The app domain
// will cache the assembly based on identity, however,
// so it could be looking in the previous version
// of the assembly and not finding the type. We work
// around this by looking for the non-assembly qualified
// name, which causes the domain to raise a type
// resolve event.
t = Type.GetType(typeName.Substring(0, commaIndex));
}
return t;
}

This will trim off the assembly portion of the string and just call Type.GetType("System.Drawing.SizeConverter").

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.

@vitek-karas
Copy link
Member

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.

@rogerge88
Copy link
Author

Thank you all. We will study it and apply it in our application for testing. Thanks.

@eerhardt eerhardt added the linkable-framework Issues associated with delivering a linker friendly framework label Feb 15, 2021
@ghost
Copy link

ghost commented Feb 15, 2021

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @tannergooding, @sbomer
See info in area-owners.md if you want to be subscribed.

Issue Details

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

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: rogerge88
Assignees: -
Labels:

area-System.Drawing, bug, linkable-framework

Milestone: 6.0.0

@rogerge88
Copy link
Author

rogerge88 commented Feb 16, 2021

@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.

@eerhardt
Copy link
Member

Reopening, as we need to fix the product to support this out of the box.

@rogerge88
Copy link
Author

@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:
------------Error message below-----
021-02-16T16:18:53.3623358Z C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(88,5): error MSB6006: "dotnet.exe" exited with code 255. [Client.csproj]
2021-02-16T16:18:53.3637813Z Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
2021-02-16T16:18:53.3654873Z C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(41,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [Client.csproj]

@eerhardt
Copy link
Member

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 ILLink.Descriptors.xml file exists on the machine and is next to the Client .csproj.

@rogerge88
Copy link
Author

@eerhardt The issues has been fixed and we can get the correct result coming from the server.

Thank you!

@rogerge88
Copy link
Author

rogerge88 commented Mar 10, 2021

@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.
------------Code below----------

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,
    }
 var category = EnumHelper.GetEnumCategory(AnEnum.Somthing);

category local result = "category", after deployment result = "PropertyCategorycategory"

Please let me know if you need more info about this issue. Thanks!

@rogerge88
Copy link
Author

rogerge88 commented Mar 12, 2021

-----Could you please give us some suggestion for above the new related issue? Thanks!

@eerhardt
Copy link
Member

@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.

@rogerge88
Copy link
Author

@eerhardt Got it and thank you very much!

We will check this new issue at #49554. Thanks!

@eerhardt eerhardt self-assigned this May 11, 2021
@eerhardt
Copy link
Member

This may be fixed by the work we've done for facades. Assigning to myself to re-test.

@eerhardt
Copy link
Member

This is now fixed with the latest bits. Closing.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Drawing bug linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

No branches or pull requests

7 participants