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

Exception when calling MessagePackSerializer.Get<T> in SL5 #205

Closed
ericontilt opened this issue Dec 8, 2016 · 7 comments
Closed

Exception when calling MessagePackSerializer.Get<T> in SL5 #205

ericontilt opened this issue Dec 8, 2016 · 7 comments
Labels
bug Detected as bug

Comments

@ericontilt
Copy link

When calling MessagePackSerializer.Get in SL5 (where T is some complex object) I get the following exception

Attempt by method 'MsgPack.Serialization.ReflectionExtensions.CreateInstancePreservingExceptionType(System.Type, System.Object[])' to access method 'MsgPack.Serialization.DefaultSerializers.GenericSerializer+ListInstanceFactory`1<System.__Canon>..ctor()' failed.

I'm using version 0.8.0. Any pointer as to what this means?

My stack trace is:

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at MsgPack.Serialization.ReflectionExtensions.CreateInstancePreservingExceptionType(Type type, Object[] constructorParameters)
at MsgPack.Serialization.DefaultSerializers.GenericSerializer.CreateListSerializer(SerializationContext context, Type itemType, PolymorphismSchema schema)
at MsgPack.Serialization.DefaultSerializers.GenericSerializer.Create(SerializationContext context, Type targetType, PolymorphismSchema schema)
at MsgPack.Serialization.DefaultSerializers.GenericSerializer.Create[T](SerializationContext context, PolymorphismSchema schema)
at MsgPack.Serialization.SerializationContext.GetSerializer[T](Object providerParameter)
at MsgPack.Serialization.SerializationContext.SerializerGetter1.Get(SerializationContext context, Object providerParameter) at MsgPack.Serialization.SerializationContext.SerializerGetter.Get(SerializationContext context, Type targetType, Object providerParameter) at MsgPack.Serialization.SerializationContext.GetSerializer(Type targetType, Object providerParameter) at MsgPack.Serialization.ReflectionSerializers.ReflectionSerializerHelper.GetMetadata(Type targetType, IList1 members, SerializationContext context, Func2[]& getters, Action2[]& setters, MemberInfo[]& memberInfos, DataMemberContract[]& contracts, MessagePackSerializer[]& serializers)
at MsgPack.Serialization.ReflectionSerializers.ReflectionObjectMessagePackSerializer1..ctor(SerializationContext context) at MsgPack.Serialization.MessagePackSerializer.CreateReflectionInternal[T](SerializationContext context, Type concreteType, PolymorphismSchema schema) at MsgPack.Serialization.MessagePackSerializer.CreateInternal[T](SerializationContext context, PolymorphismSchema schema) at MsgPack.Serialization.SerializationContext.GetSerializer[T](Object providerParameter) at MsgPack.Serialization.SerializationContext.SerializerGetter1.Get(SerializationContext context, Object providerParameter)
at MsgPack.Serialization.SerializationContext.SerializerGetter.Get(SerializationContext context, Type targetType, Object providerParameter)
at MsgPack.Serialization.SerializationContext.GetSerializer(Type targetType, Object providerParameter)
at MsgPack.Serialization.ReflectionSerializers.ReflectionSerializerHelper.GetMetadata(Type targetType, IList1 members, SerializationContext context, Func2[]& getters, Action2[]& setters, MemberInfo[]& memberInfos, DataMemberContract[]& contracts, MessagePackSerializer[]& serializers) at MsgPack.Serialization.ReflectionSerializers.ReflectionObjectMessagePackSerializer1..ctor(SerializationContext context)
at MsgPack.Serialization.MessagePackSerializer.CreateReflectionInternal[T](SerializationContext context, Type concreteType, PolymorphismSchema schema)
at MsgPack.Serialization.MessagePackSerializer.CreateInternal[T](SerializationContext context, PolymorphismSchema schema)
at MsgPack.Serialization.SerializationContext.GetSerializer[T](Object providerParameter)
at MsgPack.Serialization.MessagePackSerializer.Get[T](SerializationContext context, Object providerParameter)
at MsgPack.Serialization.MessagePackSerializer.Get[T](SerializationContext context)
at MsgPack.Serialization.MessagePackSerializer.GetT

@yfakariya yfakariya added the bug Detected as bug label Dec 9, 2016
@yfakariya
Copy link
Member

yfakariya commented Dec 9, 2016

Thank you for reporting!
Would you tell me about where did you run the problem? It might be related to code access security.

@ericontilt
Copy link
Author

Sure. It's in the callback handler of a web request. What's interesting though, is that we have version 0.4 in production code and it works fine. I literally updated the package version and changed the line of invocation from .Create to .Get. That's it.

By the way, I also tried with version 0.6, and I get a bit more detail with my exceptions. It first throws on one of my custom types (a custom Date class), but it will also throw on something like TimeSpan. Again, with no changes on the backend in the data class which worked fine with the older version.

@yfakariya
Copy link
Member

Thank you for interesting information. I fixed a lot for Xamarin and Unity support in 0.5, it may affect something. I will investigate it.

yfakariya added a commit that referenced this issue Jan 8, 2017
P/Invoke causes verification error in Windows Native.
It gains performance for edge case -- comparing (relatively) large blob (not string).
It is clearly rare, and it may bring packaging issue in future.
In addition, it is not so bad naive managed loop. In best (or worst) case, it only 1.8x slower than memcmp.
Although it is 12x slower when it is well aligned bytes, but it should be rare in real world.

So, memcmp has gone.
@yfakariya
Copy link
Member

I confirmed that this issue is caused by code access security. I'm fixing this issue.

@ericontilt
Copy link
Author

Ok, cool. Please let me know if there's anything I can do to help test it.

@carldiegelmann
Copy link

When will this fix be available in any version? Also in 0.8.2? Thanks!

@yfakariya
Copy link
Member

0.9.0. I'm fixing #202 now, and then I will release rc.

yfakariya added a commit that referenced this issue Feb 11, 2017
This fixes build errors caused by #205 and #206 change.
yfakariya added a commit that referenced this issue Feb 11, 2017
This fixes build errors caused by #205 and #206 change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Detected as bug
Projects
None yet
Development

No branches or pull requests

3 participants