Consume a .NET Assembly from a classic ASP page

I haven’t really done a lot with strongly named assemblies or interop so, this morning I thought that I’d be bold and try a little experiment; I thought that I’d create a .dll in Visual Basic .NET and consume it from a classic ASP page – seems pretty trivial, so off I went:

1) Open New Project named “SimpleDLL”assembly name “SimpleDLL“, namespace “SimpleDLL“
2) Create a class named “SimpleClass”

Public Class SimpleClass
    Public Function WriteName(ByVal name As String) As String
        Return name
    End Function
End Class
3) Register the assembly in the Registry
4) Register it for COM

    regasm /tlb SimpleDLL.dll

Yup !!  A quick check of the HKEY\LocalMachine\Software\Classes\ tells me that I had (at least) some level of success and that the Assembly is, indeed in the registry.  So, off I go to create my classic asp page and consume it.  So, again…

5) Open Visual Studio
6) Create SimplePage.asp
7) Type the following into a page named SimplePage.asp:

Dim foo
Set foo = Server.CreateObject("SimpleDLL.SimpleClass")
Response.Write foo.WriteName("blah")

 

Sure enough, it didn’t work.  OOPS….!!!!!!

The page cannot be displayed

Error Type:
(0×80070002)
/SimplePage.asp, line 11

After a bit of head scratching it was apparent that the source of my problems was that there was not enough information for the file to be found. Therefore I decided that I needed to create a strong name for my assembly and register it in the GAC

8) Generate a public/private key pair

    sn -k MarkItUp.key

9) Add the attribute to my assembly for registering it:

     <Assembly: AssemblyKeyFile(“C:\MarkItUp.key”)>

10) Re-build the assembly
11) Install it into the GAC

    gacutil /i SimpleDLL.dll

12) Re-install it into the registry
Fire-up the asp page.

Did it work? Yep :-) Amazing eh?  Now I just have to work out how to get that type library information into the registry so that I can also get intellisense working while coding the asp page.

Leave a Comment