0

情况很复杂(我的英语很基础),但让我们试着解释一下:

我正在开发一个从外部 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 并重新启动,但出现相同的错误。

感谢您的阅读,我希望有人可以提供帮助。

(抱歉语法或拼写错误!(我是意大利人..))

尼古拉

4

1 回答 1

1

尝试将所有外部 .NET dll 放入您网站的 bin 目录中。

当您在 Visual Studio 中将引用添加到单独的库或项目时,它通常会将 DLL 从该项目复制到您网站的 BIN 目录中,但它不会总是抓取该项目所依赖的 DLL 文件。

因此,如果:yourwebsite.dll --> helper.dll --> helperComponent.dll --> widget.dll(其中 --> 是一个引用),当您构建时,只有 helper.dll 最终会在您的网站旁边的 bin 目录中。 dll。您通常希望将所有这些都放在同一个地方。那么你不应该担心你的路径或任何那些东西。

或者,如果所有这些程序集都是强命名的,则可以使用 gacutil 将它们添加到全局程序集缓存中,并通过它们的标识符而不是文件来引用它们。

这是一本关于项目组织的很好的读物。“复制本地”部分涉及到这一点。您可以在 Post Build 事件中设置 xcopy,以将这些 2 级和 3 级引用放在解决方案文件下方的 bin 目录中。

http://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/

于 2011-02-19T22:14:05.467 回答