我有一个在某些 C# 代码中引用的 COM 程序集(我们称之为 com1.dll)。当我添加参考时,我在参考节点下看到一个 Interop.com1.dll。如果我从 Visual Studio 执行应用程序,以下代码将运行良好。
public void DoStuff()
{
var customer = new com1.Customer();
customer.DoSomething();
}
然后我运行我的构建脚本,执行以下 nAnt:
<tlbimp output="Interop.com1.dll" typelib="com1.dll" namespace="com1"/>
和
<csc output="myapp.exe" target="winexe" debug="true">
<sources>
...
</sources>
<references>
<include name="Interop.com1.dll"/>
...
</references>
</csc>
当我执行从构建脚本生成的程序集时,它会在var customer = new com1.Customer();
代码行上出错,并带有以下堆栈跟踪:
System.Runtime.Serialization.SerializationException: The input stream is not a valid binary format. The starting contents (in bytes) are: 44-65-76-45-78-70-72-65-73-73-2E-58-74-72-61-45-64 ...
at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializationHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at System.ComponentModel.Design.DesigntimeLicenseContextSerializer.Deserialize(Stream o, String cryptoKey, RuntimeLicenseContext context)
at System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey(Type type, Assembly resourceAssembly)
at System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo(Int32& fDesignTime, IntPtr& bstrKey, RuntimeTypeHandle rth)
at MyApp.MyClass.DoStuff()
我的问题是有人知道为什么吗?