Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Serialization in Mono throws an exception #8

Closed
Devicated opened this Issue · 8 comments

5 participants

Devicated Stephen McKamey Felipe Martijn Bogaard Miguel de Icaza
Devicated

As part of a project I’ve been using the JsonFx library. It is great to use and I’m still very positive about it.
However, I’ve been having an issue. Whenever I try to serialize a collection (both generic and non-generic) using the Mono Framework, I encounter the following exception:

Unhandled Exception: JsonFx.Serialization.SerializationException: Invalid IL cod
e in (wrapper dynamic-method) object: (object): IL_0001: callvirt  0x00000001

---> System.InvalidProgramException: Invalid IL code in (wrapper dynamic-method
) object: (object): IL_0001: callvirt  0x00000001


  at (wrapper managed-to-native) System.Delegate:CreateDelegate_internal (System
.Type,object,System.Reflection.MethodInfo,bool)
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgume
nt, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean all
owClosed) [0x0032c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class
\corlib\System\Delegate.cs:260
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodI
nfo method, Boolean throwOnBindFailure) [0x00000] in C:\cygwin\tmp\monobuild\bui
ld\BUILD\mono-2.10.1\mcs\class\corlib\System\Delegate.cs:273
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodI
nfo method) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\cla
ss\corlib\System\Delegate.cs:278
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateTy
pe) [0x0002f] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class\corli
b\System.Reflection.Emit\DynamicMethod.cs:168
  at JsonFx.CodeGen.DynamicMethodGenerator.GetPropertyGetter (System.Reflection.
PropertyInfo propertyInfo) [0x00000] in <filename unknown>:0
  at JsonFx.Serialization.Resolvers.MemberMap..ctor (System.Reflection.PropertyI
nfo propertyInfo, DataName dataName, JsonFx.Serialization.Resolvers.ValueIgnored
Delegate isIgnored) [0x00000] in <filename unknown>:0
  at JsonFx.Serialization.Resolvers.ResolverCache.BuildMap (System.Type objectTy
pe, IDictionary`2& maps) [0x00000] in <filename unknown>:0
  at JsonFx.Serialization.Resolvers.ResolverCache.LoadTypeName (System.Type type
) [0x00000] in <filename unknown>:0
  at JsonFx.Model.ModelWalker.GetTypeName (System.Object value) [0x00000] in <fi
lename unknown>:0
  at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1
tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unkno
wn>:0
  at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 token
s, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>
:0
  at JsonFx.Model.ModelWalker.GetObjectTokens (System.Collections.Generic.List`1
tokens, ICycleDetector detector, DataName typeName, IDictionaryEnumerator enume
rator) [0x00000] in <filename unknown>:0
  at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1
tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unkno
wn>:0
  at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 token
s, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>
:0
  at JsonFx.Model.ModelWalker.GetTokens (System.Object value) [0x00000] in <file
name unknown>:0
  at JsonFx.Serialization.DataWriter`1[JsonFx.Model.ModelTokenType].Write (Syste
m.Object data) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---

The weird thing is that in the .NET framework, everything works fine!

I’m using the following bit of code to convert the object to JSON:

dynamic el = new ElasticObject();

el.test = "value";

List<Dictionary<string, object>> result = new List<Dictionary<string, object>>(); // Usually a result from a MySQL query
el.result = result;

Hashtable jsonObject = DynamicExtensions.HashtableFromElastic(el);
JsonFx.Json.JsonWriter writer = new JsonFx.Json.JsonWriter();
string jsonString = writer.Write(jsonObject);

Using:

  • Latest signed .NET 4.0 build (version 2.0.0.0 according to the properties)
  • Mono 2.10.1
  • Ubuntu 10.04, but it also occurs on Windows 7 (still using Mono of course)

According to http://www.mono-project.com/Compatibility, dynamics are completely supported since Mono 2.8

Stephen McKamey
Owner

Thanks for submitting the details. I'll try to take a look at this in the next couple days.

Stephen McKamey mckamey closed this in 719a11a
Stephen McKamey mckamey reopened this
Stephen McKamey
Owner

Unfortunately the problem hasn’t been fixed. The problem now occurs in OpCodes.Call

System.InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object: (object): IL_0001: call      0x00000001

Reverting change as subtle issues might result from using OpCodes.Call on virtual methods.

Felipe

Hi, i'm having the same problem. Whenever a I try to serialize an object that contains a collection or a more complex object.

Stephen McKamey
Owner

Unfortunately, I am not knowledgable enough in Mono to know what needs to change to make it work. I don't even have an environment set up where I can properly reproduce this situation.

Also, I've been swamped lately with a startup that I'm building. In the next few weeks, my first kid is to be born which I anticipate will further consume my spare time. So I'm afraid that I can't really promise anything any time soon. What I can do is help guide you on what should be looked at to change. My next steps would also be to ping the Mono guys to get a better sense of why the code snippet is failing.

Stephen McKamey
Owner

Thanks! Also I pinged Miguel de Icaza and this was his response:

http://twitter.com/#!/migueldeicaza/status/115854875094548482

Assuming that dynamic-method generation is supported in Mono (I haven't confirmed that myself), then this might actually be a Mono issue or perhaps just need a workaround for their implementation.

Martijn Bogaard

Hi,

Have you be able to make some progress on this?

Miguel de Icaza

The bug was filed, but it did not include a small test case, instead it includes a big dependency on jsonfx.

What this error means is that our verifier is not accepting the code that you are sending.

Stephen McKamey
Owner

Adding a link to the Mono Bugzilla report: https://bugzilla.xamarin.com/show_bug.cgi?id=6821

If someone with a Mono environment is able to create a simple repro, this should be the method which is causing issue:

https://github.com/jsonfx/jsonfx/blob/master/src/JsonFx/CodeGen/DynamicMethodGenerator.cs#L162

Stephen McKamey mckamey closed this in 1911838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.