1

同じディレクトリ内の別のファイルと同じ名前 ( .dllの前の部分) を持つアセンブリを参照すると、IronPython で問題が発生します。

たとえば、Foo.xmlFoo.Xml.dllが同じディレクトリにある場合、ディレクトリは sys.path に追加され、アセンブリFoo.Xmlを参照しようとします。

clr.AddReference("Foo.Xml")

次のエラーが発生します。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: System.IO.IOException: Could not add reference to assembly Foo.Xml
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.<RunOneInteraction>b__0()

これは、呼び出しに.dll拡張子を含めるだけで回避できます。AddReference()

ただし、参照されているアセンブリの依存関係であいまいさが発生すると、これは制御できなくなります。たとえば、アセンブリFoo.dllがFoo.Xml.dllに依存しているとします。IronPython がこの依存関係を内部的に解決しようとすると、前述の名前の競合が発生して失敗します。エラーはやや冗長ですが、問題は同じようです。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] Could not load file or assembly 'Foo.Xml, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

どちらの場合も、Foo.xmlファイルの名前を変更すると、Foo.Xml.dllアセンブリの読み込みが成功するか失敗するかが異なります。

誰もこれを経験したことがありますか?誰にも回避策がありますか?より良いアプローチ?

4

0 に答える 0