rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
225 stars 29 forks source link

'System.Reflection.Emit.Lightweight' was not included in compilation, but was referenced in NetJSON.DynamicNetJSONSerializer.CreateDeserializerWithTextReader() #202

Closed Nexxkinn closed 5 years ago

Nexxkinn commented 5 years ago

My app works on debug mode, but throws this error if I compile it in release mode

 {System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> 
System.MissingMethodException: Method 'DynamicMethod..ctor(string, Type, Type[], Module, bool)' from assembly 'System.Reflection.Emit.Lightweight' was not included in compilation, but was referenced in NetJSON.DynamicNetJSONSerializer.CreateDeserializerWithTextReader(). There may have been a missing assembly, or a dependency on a more recent Windows SDK release.
   at NetJSON.NetJSON.DynamicNetJSONSerializer`1..ctor()
   at NetJSON.NetJSON.NetJSONCachedSerializer`1.GetSerializer()
   at NetJSON.NetJSON.NetJSONCachedSerializer`1..cctor()
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext* pContext) in f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Runtime\CompilerServices\ClassConstructorRunner.cs:line 92
   }

other computers from Microsoft also returns the same kind of error image

might be related : Microsoft delisted System.Reflection.Emit.Lightweight for .NET Standard Should there be a .Net Standard 2.0 version of Reflection.Emit?

rpgmaker commented 5 years ago

Strange that this is happening. My .net standard test work fine. It should have failed even for the simple calls. I will look into it and get back to you .

Thanks for the find.

rpgmaker commented 5 years ago

I tested it again and it works fine with .net core 2.0+ without any issue. How are you consuming it?

image

Nexxkinn commented 5 years ago

It does works in debug mode. But it throws an error if you build it on release mode, in my experience.

rpgmaker commented 5 years ago

Ok. i will try running in release mode. Thanks

rpgmaker commented 5 years ago

It also works in release mode.

image

rpgmaker commented 5 years ago

Could you give me a code sample i can test with?

Thanks,

Nexxkinn commented 5 years ago

As same as this code I upload in the previous issue. https://github.com/rpgmaker/NetJSON/issues/199#issuecomment-414015990

might be related to the issue is that System.Reflection.Emit is not supported in UWP's AOT compiler https://github.com/dotnet/corefx/issues/29808

Can you apply and check whether this solution works? https://github.com/mgravell/protobuf-net/issues/388 https://github.com/mgravell/protobuf-net/commit/72558ee322c51aea4fb7ec05eb92190a125f9e0f

rpgmaker commented 5 years ago

I will take a look at it and let you know. Thanks

rpgmaker commented 5 years ago

The changes was to remove Emitting of IL which i cannot remove since I need it in either dynamic assembly or dynamic method generation. Does DynamicMethod exists in UWP? if so then i can conditionally generate dynamic methods instead of seperate dynamic assembly.

Nexxkinn commented 5 years ago
      The changes was to remove Emitting of IL which i cannot remove since I need it in either dynamic assembly or dynamic method generation. Does DynamicMethod exists in UWP? if so then i can conditionally generate dynamic methods instead of seperate dynamic assembly.

UWP ( and generally, any .Net Native-compiled apps ) doesn't support Reflection.Emit library, due to the nature of .Net Native apps to be run in AOT instead of JIT. I just realised this yesterday :/

Oh well, you can close this issue since it's .Net Native's problem instead.

rpgmaker commented 5 years ago

Thanks for verifying. 😀