XML Serializer抛出异常:"找不到方法"

时间:2015-06-18 14:57:06

标签: .net xml xml-serialization mstest

var txnSerializer = new TxnSerializer(); //generated serializer
TextWriter writer = new StringWriter();
txnSerializer.Serialize(writer, response.ReturnValue);

抛出以下异常:

System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=There was an error generating the XML document.
  Source=System.Xml
  StackTrace:
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
       at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
       at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
       at Tests.MiscTests.MyTest() in c:\dev\MiscTests.cs:line 377
  InnerException: System.MissingMethodException
       HResult=-2146233069
       Message=Method not found: 'Project.ClosingInstructionsType Project.Txn.get_ClosingInstructions()'.
       Source=Project.Schema.XmlSerializers
       StackTrace:
            at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1761_Txn(String n, String ns, Txn o, Boolean isNullable, Boolean needType)
            at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3518_Txn(Object o)
            at Microsoft.Xml.Serialization.GeneratedAssembly.TxnSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
            at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
       InnerException: 

这里有一个奇怪的部分:除了我的以外,它在团队中的所有其他开发工作站上都​​能正常工作。这是许多失败测试中的一个,所有失败都有相同的错误。救命啊!

1 个答案:

答案 0 :(得分:1)

System.MissingMethodException几乎总是不正确的.NET应用程序环境的症状(例如,DLL版本不匹配)。我会尝试以下行动:

  • 重建并重新部署整个解决方案。根据您的部署选项,您可能希望在重新部署之前删除(清除)部署文件夹中的所有现有.DLL。当旧程序集在它们不应存在的位置挥之时,就会发生此异常。重新部署后重新启动IIS。
  • 使用gacutil /u DLL_NAME从GAC中删除所有相关程序集。在此之后重新启动IIS。使用gacutil /if "<path to the assembly .dll file>"
  • 重新安装GAC中所需的正确程序集