Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

SerializationNotSupportedType when serializing ImmutableHashSet even when trimming is disabled for Blazor WebAssembly app

$
0
0

I have a Blazor app that serialize JSON to send back to the API server like this:

    public HttpRequestMessage CreateWithBody<T>(string path, HttpMethod method, T body)    {        var req = Create(path, method);        req.Content = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");        return req;    }

Only when published, I have this exception:

System.NotSupportedException: SerializationNotSupportedType, System.Collections.Immutable.ImmutableHashSet`1[System.String]   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_SerializationNotSupported(Type )   at System.Text.Json.Serialization.IEnumerableConverterFactoryHelpers.GetImmutableEnumerableCreateRangeMethod(Type , Type )   at System.Text.Json.Serialization.Metadata.ReflectionEmitMemberAccessor.CreateImmutableEnumerableCreateRangeDelegate(Type , Type , Type )...   at System.Text.Json.JsonSerializer.GetTypeInfo[CfZoneDnsAddRequest](JsonSerializerOptions )   at System.Text.Json.JsonSerializer.Serialize[CfZoneDnsAddRequest](CfZoneDnsAddRequest , JsonSerializerOptions )   at TypeName.CreateWithBody[CfZoneDnsAddRequest](String path, HttpMethod method, CfZoneDnsAddRequest body)

Before I had an issue with ImmutableArray<T> but adding this helped:

public record AnotherType(    [field: DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ImmutableArray<string>))]ImmutableArray<string> Texts,    ImmutableArray<int> LanguageIds);

But now with this new type, somehow nothing helps at all:

public record ProblematicType(    string Ip,    [field: DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ImmutableHashSet<string>))]     ImmutableHashSet<string> Names);

I even add this to my Blazor project and my ASP.NET Core project (that serves the Blazor):

<IsTrimmable>false</IsTrimmable><PublishTrimmed>false</PublishTrimmed>

What else do I need to do to serialize that one?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>