Search code examples
c#asp.netdll.net-assembly

Use an assembly in an aspx page


I have a very simple aspx script:

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

The MimeKit.dll is in the same folder as this script.

I find answers that tell me to put it in the bin folder. I don't have a bin folder, this is just a single file - not created in Visual Studio and not part of a project or app.

Can anyone tell me what I need to do, that does not involve using Visual studio, to be able to use this dll.

I get error:

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

I run the script like so:

http://localhost/test/mail.aspx

I have created a bin folder at http://localhost/bin and put the dll in there. I have also created a bin folder at http://localhost/test/bin. I get the same error.

Have also tried:

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

which said it was successful, but still I get the same error.

Also did the gacutil using the Developer Command Prompt for VS 2017 - made no difference.

Also added the following to 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>

Still no go - same error message. (Note: I got the public key token by using gacutil /l MimeKit.

Discovered that MimeKit has a dependency (BouncyCastle.Crypto.dll), so tried just using that:

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

Same error and this has no dependencies.

Pulling my hair out - does anyone know how to do this?


Solution

  • OK - I was barking up the wrong tree. This is what I needed. Didn't need to register the dll, just needed to put it in the folder: http://localhost/bin

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