【问题标题】:Use an assembly in an aspx page在 aspx 页面中使用程序集
【发布时间】:2019-05-22 09:45:22
【问题描述】:

我有一个非常简单的 aspx 脚本:

<%@ Page Language="C#" Debug="true" %>
<%@ Assembly Name="MimeKit.dll" %>
<%
Response.Write("test");
%>

MimeKit.dll 与此脚本位于同一文件夹中。

我找到了告诉我将其放入 bin 文件夹的答案。我没有 bin 文件夹,这只是一个文件 - 不是在 Visual Studio 中创建的,也不是项目或应用程序的一部分。

谁能告诉我我需要做什么,不涉及使用 Visual Studio,才能使用这个 dll。

我得到错误:

Could not load file or assembly 'MimeKit.dll' or one of its dependencies. The system cannot find the file specified.

我像这样运行脚本:

http://localhost/test/mail.aspx

我在http://localhost/bin 创建了一个bin 文件夹并将dll 放在那里。我还在http://localhost/test/bin 创建了一个 bin 文件夹。我得到同样的错误。

也试过了:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\gacutil.exe" /i MimeKit.dll

说它成功了,但我仍然得到同样的错误。

gacutil 也使用了 VS 2017 的开发人员命令提示符 - 没有任何区别。

还在 web.config 中添加了以下内容:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="myAssembly" publicKeyToken="bede1c8a46c66814" culture="neutral" />
            <codeBase version="2.1.0.0" href="http://localhost/bin/MimeKit.dll"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

仍然不行 - 相同的错误消息。 (注意:我通过gacutil /l MimeKit获得了公钥令牌。

发现 MimeKit 有一个依赖项(BouncyCastle.Crypto.dll),所以尝试使用它:

<%@ Page Language="C#" Debug="true" %>
<%@ Assembly Name="BouncyCastle.Crypto.dll" %>
<%
Response.Write("test");
%>

同样的错误,这没有依赖关系。

拔掉我的头发 - 有人知道怎么做吗?

【问题讨论】:

    标签: c# asp.net dll .net-assembly


    【解决方案1】:

    好吧 - 我叫错树了。这就是我需要的。不需要注册dll,只需要把它放在文件夹中:http://localhost/bin

    <%@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="MimeKit" %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多