1

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()

私の質問は、誰かが理由を知っていますか?

4

1 に答える 1

2

私はこれを理解しました。アプリケーションに<project>\Properties\Licenses.licxファイルがあることがわかりました。NAnt からアプリケーションを構築するとき、そのファイルを<csc><resources/></csc>ブロックに含めていました。何らかの理由で、相互運用参照を追加するまでこれは機能しました。

私がしなければならなかったことは、NAnt<license/>タスクを使用して licx からライセンス ファイルを作成することでした。そのタスクからの出力により、ビルド スクリプト<project>\Properties\LIcenses.licxの一部のファイルが置き換えられました。<csc><resources/></csc>

それで、ボブは本当に私の叔父でした。

于 2011-07-07T13:36:09.110 に答える