Aspnetcore: Object reference not set to an instance of an object.

Created on 17 May 2018  路  9Comments  路  Source: dotnet/aspnetcore

I am getting the following error after including Newtonsoft.Json(version 11.0.2) package

Uncaught Error: Newtonsoft.Json.JsonSerializationException: Error setting value to 'TargetId' on 'BlazorApp1.Message'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Linq.Expressions.Interpreter.LightLambda.MakeRunDelegateCtor (System.Type delegateType) <0x1d7f658 + 0x00308> in :0
at System.Linq.Expressions.Interpreter.LightLambda.GetRunDelegateCtor (System.Type delegateType) <0x1d78e70 + 0x00048> in :0
at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) <0x1d78ce8 + 0x0000e> in :0
at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) <0x1d783c0 + 0x00024> in :0
at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () <0x1d78250 + 0x0000a> in :0
at System.Linq.Expressions.LambdaExpression.Compile (System.Boolean preferInterpretation) <0x205a910 + 0x00018> in :0
at System.Linq.Expressions.LambdaExpression.Compile () <0x205a8d8 + 0x0000a> in :0

image

area-blazor

Most helpful comment

@abhishekgoenka Could you please try out your scenario with this linker config and see if it resolves your issue?

All 9 comments

Yes, this is a known issue (https://github.com/aspnet/Blazor/issues/370) that we hope will be resolved with the next Mono update (#831)

Has this issue been addressed with 0.4.0? I'm having an issue with trying to serialize and deserialize using Newtonsoft (originally in 0.3.0, then updated this morning to 0.4.0) with a simple class (it errors on an int in the object). I didn't want to open another duplicate.

There are some reports from folks that this might actually be an issue with how Blazor trims out unused IL. @kiyote do you want to share the linker config you were using to get Json.NET working here?

Thanks @danroth27, hopefully that would help - what's a linker config and how does it help change how serialization happens?

@abhishekgoenka Could you please try out your scenario with this linker config and see if it resolves your issue?

@danroth27 I am using this linker. Will the same linker config work?

Blazor runs the mono linker by default as part of each build. You just need to configure it to not link out System.Linq.Expressions.* so that compiled expressions work. See https://gist.github.com/Suchiman/a5e65f40c353120c9cf7f6a631ded28b

It works with linker.xml file.

it work also for AutoMapper @danroth27 thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

farhadibehnam picture farhadibehnam  路  3Comments

UweKeim picture UweKeim  路  3Comments

ipinak picture ipinak  路  3Comments

FourLeafClover picture FourLeafClover  路  3Comments

rbanks54 picture rbanks54  路  3Comments