Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

TypeMock as Invalid Program

+1 vote
I have traced a problem down to TypeMock but not sure how extensive the problem is. All the issues started popping up with the latest source of NHibernate from the trunk so I thought the issue was there. Basically running the unit tests for NHibernate would produce an error similiar to this.

NHibernate.Test.CfgTest.ConfigurationFixture.CacheConfiguration : NHibernate.MappingException : Could not compile the mapping document: NHibernate.DomainModel.ABC.hbm.xml

  ----> System.InvalidOperationException : There is an error in XML document (0, 0).

  ----> System.InvalidProgramException : Common Language Runtime detected an invalid program.


basically its an issue with the XmlSerializer and TypeMock. After working with the NHibernate team and nobody could reproduce the error, I found this post http://forums.microsoft.com/MSDN/ShowPo ... 5&SiteID=1

The reporter ultimately figured out that uninstalling TypeMock fixed the problem. I simply disabled TypeMock from Vs.Net and that resolved the problem. ReEnabled TypeMock and the problem returned.

The issue seems to stem from a conflict between TypeMock and The XmlSerializer because the issue the NHibernate tests are with the XmlSerializer just as the poster describes in the link above.

Partial stack from NHibernate is

       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract..ctor()

          --- End of inner exception stack trace ---

       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)

       at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

       at NHibernate.Cfg.XmlHbmBinding.Binder.Deserialize[T](XmlNode node)


I saw that there are other issues with the CLR detecting an Invalid program and TypeMock on this forum. Hopefully this issue is being fixed. Otheriwse, let me know if I can provide more information to get this issue resolved.

Jesse
asked Jan 8, 2008 by juice_johnson (1,580 points)

33 Answers

+1 vote
Hi Jesse,

Thanks for offering your help. Let's take this offline - I'l write a separate mail.
answered Jan 8, 2008 by gilz (20,200 points)
+1 vote
We are having the exact same issue. NHibernate and typemock does not work in mconjunction with eachother when using XML Mapping documents. Can I get in on this?

mattias [at] fatstatement dottcomm
answered Jan 11, 2008 by M. Johansson (400 points)
0 votes
Hi
Tanks for reporting.
We will update you about what's going on with this issue as well.
answered Jan 11, 2008 by ohad (37,080 points)
+1 vote
Hi,

I am using TypeMock and experiencing similar issues.

We are using nant to run our build. Nunit running tests and TypeMock version 4.1.0.0. We are running ncover for code coverage.

Please can you include me on an update on this thread.
Dean_vr at yahoo dot com

Running tests in resharper pass. Running builds with tests that use XmlSerializer Serialize fail with error:

[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write18_ResultSetOfSupplier(Object o)[exec] 2) RetrieveSupplierVenuePageDetails : System.InvalidOperationException : There was an error generating the XML document.[exec] ----> System.InvalidProgramException : Common Language Runtime detected an invalid program.[exec] at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)[exec] at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)[exec] at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)[exec] at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o)[exec] at SerializeObject(Object pObject) in WebServiceHelperTest.cs:line 2508[exec] at RetrieveSupplierVenuePageDetails() in WebServiceHelperTest.cs:line 2288[exec] --InvalidProgramException[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write6_Currency(String n, String ns, Currency o, Boolean isNullable, Boolean needType)[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write8_SupplierPackage(String n, String ns, SupplierPackage o, Boolean isNullable, Boolean needType)[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write16_Supplier(String n, String ns, Supplier o, Boolean isNullable, Boolean needType)[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write17_ResultSetOfSupplier(String n, String ns, ResultSet`1 o, Boolean isNullable, Boolean needType)[exec] at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterResultSet1.Write18_ResultSetOfSupplier(Object o)
answered Jan 17, 2008 by dean2008 (670 points)
+1 vote
ps. this is the line of code it dies on:


      private static String SerializeObject(Object pObject) {
         MemoryStream memoryStream = new MemoryStream();
         XmlSerializer xs = new XmlSerializer(pObject.GetType());
         XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
         xs.Serialize(xmlTextWriter, pObject); // dies here
         memoryStream = (MemoryStream) xmlTextWriter.BaseStream;
         string xmlString = UTF8ByteArrayToString(memoryStream.ToArray());
         return xmlString;
      }


not sure if this is an nant issue or typemock...

thanks!
answered Jan 17, 2008 by dean2008 (670 points)
+1 vote
Hi,

Thanks for reporting this. The more information we have, we can help resolve this. We'll keep everyone updated on this issue.
answered Jan 17, 2008 by gilz (20,200 points)
+1 vote
Hi,

do you have a rough eta on this?

thanks,
answered Jan 21, 2008 by dean2008 (670 points)
+1 vote
Hi,

do you have a rough eta on this?

thanks,


I second this. Our test suite is effectively broken due to this, because we cannot run database tests in live mode. It's VERY critical for us.
answered Jan 21, 2008 by M. Johansson (400 points)
0 votes
Hi
This issue is high in our list.
I can't really know when it will be fixed since we are still trying duplicate the error. :(
answered Jan 21, 2008 by ohad (37,080 points)
+1 vote
juice_johnson: I'm having trouble reproducing this error. At least for now, it does not seem to reproduce with a simple XMLSerializer, so we need to find the cause a little higher up in the chain.
Can you post some piece of code that will reproduce this? A test that uses NHibernate would be great.

Roy
answered Jan 22, 2008 by royo (2,170 points)
...