Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# COM例外情况:";SerializationException:输入流不是有效的二进制格式。“开始内容…”;_C#_Com_Tlbimp - Fatal编程技术网

C# COM例外情况:";SerializationException:输入流不是有效的二进制格式。“开始内容…”;

C# COM例外情况:";SerializationException:输入流不是有效的二进制格式。“开始内容…”;,c#,com,tlbimp,C#,Com,Tlbimp,我有一个COM程序集(我们称之为com1.dll),我在一些C#代码中引用它。添加引用时,我会在引用节点下看到Interop.com1.dll。如果从VisualStudio执行应用程序,以下代码将正常运行 public void DoStuff() { var customer = new com1.Customer(); customer.DoSomething(); } 然后运行构建脚本,执行以下nAnt: <tlbimp output="Interop.com1.

我有一个COM程序集(我们称之为com1.dll),我在一些C#代码中引用它。添加引用时,我会在引用节点下看到Interop.com1.dll。如果从VisualStudio执行应用程序,以下代码将正常运行

public void DoStuff()
{
    var customer = new com1.Customer();
    customer.DoSomething();
}
然后运行构建脚本,执行以下nAnt:

<tlbimp output="Interop.com1.dll" typelib="com1.dll" namespace="com1"/>

我的问题是有人知道为什么吗?

我知道了。该应用程序有一个
\Properties\Licenses.licx
文件。从NAnt构建应用程序时,我们将该文件包含在
块中。由于某种原因,在我添加互操作引用之前,这一直有效

我需要做的是使用NAnt
任务从licx创建一个许可证文件。该任务的输出替换了构建脚本的
部分中的
\Properties\LIcenses.licx
文件


因此,鲍勃真的是我的叔叔。

+1代表时尚。不要犹豫接受你自己的答案(如果你有足够的代表这么做?)
<csc output="myapp.exe" target="winexe" debug="true">
    <sources>
        ...
    </sources>
    <references>
        <include name="Interop.com1.dll"/>
        ...
    </references>
</csc>
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()