情况很复杂(我的英语很基础),但让我们试着解释一下:
我正在开发一个从外部 dll 调用方法的 Asp.net Web 服务。
这个外部 dll 从其他 .net dll 调用一些方法。
所以我们有:
Asp.net WS ----> External.dll ----> other.NEt.Dll(---> other .netdll)
您必须知道外部 dll 使用路径(由初始化方法给出)来解析其内部引用。
总之,我有一个 Web 应用程序,其中添加了对我的 External.dll 的引用和一个完全受信任的路径 (c:\EXTERNAL),其中包含 external.dll 所需的所有 .net dll。
环顾四周,我发现要添加到 application_START 的代码:
Dim path As String = String.Concat(System.Environment.GetEnvironmentVariable("PATH"), ";", "c:\EXTERNAL)
System.Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Machine)
这会将我的 c:\EXTERNAL 添加到全局环境 PATH。
通过从 Visual Studio 开发服务器运行此配置,我没有收到任何错误,并且一切正常。
当我在本地 IIS 服务器上发布应用程序时,它会出现各种错误:起初结果类似于:
Failure reading <Myobject> control of <(static)> type
Unable to create <myobject> object (<C:\(WRONGPATH)\needed.net.dll> assembly)
为了解决这个问题,我尝试将所需的 .net dll 添加到 wwwroot 中我的应用程序的 /bin 中,但结果类似于:
Failure reading <MyType> control of <Myobject> type
Error returned by .NET Framework:
System.ArgumentException: Un oggetto di tipo 'ComNet.BaseControl.LoginDisplayLayout' non può essere convertito nel tipo 'ComNet.BaseControl.LoginDisplayLayout'.
in System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
in System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
in System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
in System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
in CDotNetType.bSetProperty(CDotNetType* , Object gcrObj, SByte* pszNom, CSLevel* pclPile, Int32 nDimension, Int32* pnTabDimension, STOperationDotNet* pstOperation)
这次看起来它正在加载相同的 dll,但来自不同的位置导致冲突。
现在就是这样。我很难解释这个 dll 地狱,但基本上我想复制当应用程序在 Visual Studio 开发服务器中运行良好时发生的事情。我还读到 IIS 在不重新启动的情况下无法解析添加的 PATH,因此我尝试手动将 c:\external 添加到 PATH 并重新启动,但出现相同的错误。
感谢您的阅读,我希望有人可以提供帮助。
(抱歉语法或拼写错误!(我是意大利人..))
尼古拉