views:

88

answers:

1

I'm trying to have classes serialized using MS runtime and Mono runtime. While using MS runtime everything goes fine, but using Mono I give me some exception and program startup.

The following exception are thrown:

  • There was an error reflecting a type: System.TypeInitializationException (a class)
  • There was an error reflecting a type: System.InvalidOperationException (a class)
  • There was an error reflecting a field: System.ArgumentOutOfRangeException < 0 (an array of classes)

The binary was compiled using MS SDK, but I don't think this is the problem.

What's going on? .NET shouln't be portable? How to solve these exceptions?


I've installer MONO for Windows, installed Monodevelop (just for the sake) and get the same problems. Here is a class which causes the problems:

[XmlInclude(typeof(XmlServiceVersion))]
[XmlInclude(typeof(XmlUserLogin))]
[XmlInclude(typeof(XmlNetService))]
[XmlInclude(typeof(XmlUserList))]
[XmlInclude(typeof(XmlGroupList))]

public class XmlMessage
{
            ...


    [XmlAttribute]
    public XmlMessageCode Code = XmlMessageCode.Invalid;

    [XmlAttribute]
    public XmlMessageError Error = XmlMessageError.None;

    public Object Contents = null;

    private static XmlSerializer mXmlSerialize = new XmlSerializer(typeof(XmlMessage));

}

The exception text is specifically:

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for iGecko.XmlClientConfiguration ---> System.TypeInitializationException: An exception was thrown by the type initializer for iGecko.Net.XmlMessageClient ---> System.InvalidOperationException: There was an error reflecting type 'iGecko.Net.XmlMessage'. ---> System.InvalidOperationException: There was an error reflecting type 'iGecko.Net.XmlProcessList'. ---> System.InvalidOperationException: There was an error reflecting field 'Items'. ---> System.ArgumentOutOfRangeException: Cannot be negative.
Parameter name: length

I forgot to mention that this happen during the contructor which should serialize the class above.


Update

Sorry for 'grand' editing, but I'm starting to understand the error. The XmlMessage contains an Object public field, which could be assigned an XmlProcessList class, which derives from the class described in this post (XmlDictionary), which defines the Items field.

+2  A: 

Try running your application through MoMA (Mono migration analyser) - it should tell you what methods you are using that Mono does not support and any potential migration issues (i.e building paths without using Path.Combine).

Oded
It may be some overload not implemented or possibly not done correctly...
eschneider
MoMA tell me about the usual P/Invokes, but nothing that's called at runtime (of course, P/Invoke calls are WIN32 only!). Now I will provide some more info.
Luca