Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Serialization in Mono throws an exception #8

Devicated opened this Issue · 8 comments

5 participants


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
  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
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodI
nfo method, Boolean throwOnBindFailure) [0x00000] in C:\cygwin\tmp\monobuild\bui
  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
  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
  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
  at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 token
s, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>
  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
  at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 token
s, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>
  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);


  • Latest signed .NET 4.0 build (version 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, dynamics are completely supported since Mono 2.8


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

@mckamey mckamey closed this in 719a11a
@mckamey mckamey reopened this

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.


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


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.


Thanks! Also I pinged Miguel de Icaza and this was his response:!/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.



Have you be able to make some progress on this?


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.


Adding a link to the Mono Bugzilla report:

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

@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.