在将同名的程序集( .dll 之前的部分)引用为同一目录中的另一个文件时,我遇到IronPython的问题。
例如,如果 Foo.xml 和 Foo.Xml.dll 位于同一目录中,则该目录已附加到 sys.path 并尝试引用程序集 Foo.Xml :
public void setHousePrice()
{
// do stuff etc.
calculateFees(this.housePrice); // <---This probably doesn't do what you think it does
}
// No. This doesn't receive this.housePrice. It receives the VALUE of this.housePrice.
// It's a completely new variable
public void calculateFees(int housePrice) .
{
// do some stuff
}
发生以下错误:
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 扩展名即可避免这种情况。
但是,当引用的程序集的依赖关系出现歧义时,这将不再受您控制。例如,让我们说汇编 Foo.dll 取决于 Foo.Xml.dll 。当IronPython尝试在内部解决此依赖关系时,它将遇到上述名称冲突并失败。该错误略显冗长,但问题似乎相同:
AddReference()
在这两种情况下,更改 Foo.xml 文件的名称是成功加载 Foo.Xml.dll 程序集与失败之间的区别。
以前有没有人经历过这个?有没有人有解决方法?更好的方法?