Forum Discussion

matej_trampus's avatar
11 years ago

BadImageFormatException when running AQTime

I am evaluting AqTime 8.10.772.7

System_ 64 bit, Windows 7, VS 2013. Net 4.5.1, Performance Profile



I am getting BadImageFormatException - BadMethod token exception.




Debug string: Exception cought: (System.InvalidOperationException: There is an error in XML document (0, 0). ---> System.BadImageFormatException: Bad method token.


Debug string:    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract..ctor() 6652 14:11:13:016


Debug string:    --- End of inner exception stack trace --- 6652 14:11:13:016


Debug string:    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) 6652 14:11:13:016


Debug string:    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader) 6652 14:11:13:016


Debug string:    at Crea.OMSi.Common.Classes.Serialization.XmlToObject2(Byte[] xml, Type type) in 


Debug string:    at Crea.OMSi.Common.Classes.WsCache.GetFromCache(String key, T& result) 







The code, being executed is similar to the following:




        string fileName = @"SomeXml.xml";


        byte[] data = File.ReadAllBytes(fileName);


        Serialization.XmlToObject2(data, typeof(someType));



where XmlToObject2 is used to deserialize the object:


    public static object XmlToObject2(byte[] xml, System.Type type)
    {
      XmlTextReader reader = new XmlTextReader(new MemoryStream(xml));

      XmlSerializer serializer = new XmlSerializer(type);

      object o = serializer.Deserialize(reader);
      return o;
    }

This code resides in some other library assemblies, compiled for previous veriosn of .net (4.0).

However, when I try to exctract the above code and run in console application, the exception does not occur.


Any ideas om what might be wrong?



This could be related to the fact that .NET is generating Xsml serialization at run time.



Bye,

  Matej
  • Details sent to Matej outside of this forum post were:



    Most probably, there is a routine in your application being profiled that causes the exception after it is instrumented by AQtime. According to your description, the routine is "Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract..ctor", i.e. the XmlSerializerContract class' constructor. So, to avoid the exception, try adding the routine to the "Options | Routines to Ignore..." list. Please see the "Excluding Code From Profiling" article for details:

    http://support.smartbear.com/viewarticle/43211/

     

    Note: the exception can also be caused by the fact that AQtime does not officially support .NET Framework 4.5.1. In any way, if the exception persists after that, or your application crashes for another reason, please complete our AQtime Troubleshooter to help us investigate it:

    http://support.smartbear.com/troubleshooter/?prod=AQtime-8