引用位于共享驱动器上的NET
动态链接库时,会引发Python.NET
异常FileNotFoundException
。示例代码:
import sys
import clr
sys.path.append(PATH_TO_SHARED_NETWORK_DRIVE)
clr.AddReference('MY_DLL')
通过谷歌搜索,我发现真正的问题是.NET Framework
默认情况下不启用CAS策略。因此,要在共享驱动器上引用dll,需要启用loadFromRemoteSources
开关。示例代码:
from clr import System
from System import Reflection
Reflection.Assembly.LoadFrom(FULL_PATH_TO_MY_DLL.dll)
例外情况:
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
问题是我不知道如何从Python中启用loadFromRemoteSources
开关
显然,设置此设置的唯一方法是通过app.config,其内容与您提供的链接类似:
首先,尝试在与python.exe相同的文件夹中创建包含上述内容的python.exe.config文件。如果这仍然没有帮助,python.net的实用性就会减弱,因为这样你就必须创建一个实际的.net库,并在本地使用它来引用远程dll,并从那里代理你的调用。我想这应该行得通,但我还没试过
你确定你真的需要引用远程主机上的dll吗?也许你最好重新定义这个问题
相关问题 更多 >
编程相关推荐