XML 序列化程序抛出异常:"method not found"

XML Serializer throwing exception: "method not found"

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: 

这是奇怪的部分:它在团队中除我以外的所有其他开发工作站上都​​运行良好。这是许多失败的测试之一,所有测试都因相同的错误而失败。求助!

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

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