Posted by: Nishant Rana | January 28, 2008

Using .NET Assembly (DLL) in ASP page

1. Create a Assembly file using following:
        File >> New >> Project >> Class Library >> Name = MyLibCSharp
 
2. Add a function HelloWorld. Code will look as follows:

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

namespace MyLibCsharp

{

[Guid("FE1EB79E-3513-487e-ADFF-2B61C6CB4730")]

[ComVisible(true)]

public class Class1

{

public String HelloWorld(String name)

{

return (“Hellow World; Welcome “ + name);

}

}

}

3. Sign the Assembly (To enable it to be used by multiple Applications):

Go to Project >> MyLibCSharp Properties >> Signing >> Sign the Assembly >> New >> Key.snk

4. Enable for COM Interop:

Go to Project >> MyLibCSharp Properties >> Build >> Output >> Check the “Register for COM interop.

5. Build the Assembly.

6. Add to GAC using “Visual Studio Command Prompt” the assembly is located in DEBUG/RELEASE folder.

gacutil -I MyLibCSharp.dll

7. Execute the following:

Regasm /tlb /codebase MyLibCSharp.dll

8. ASP code:

<%

Dim foo

set foo = Server.CreateObject(“MyLibCSharp.Class1″)

Response.Write (foo.HelloWorld(“test”))

%>

9. To unregister the assembly

Regasm /unregister MyLibCSharp.dll

10. And to remove the same from GAC (Global assembly cache)

Go to

C:\WINDOWS\assembly

find the assembly you want to remove

select it , right click it and select uninstall

Bye

 


Responses

  1. Can you help me please?

    I am getting the following error:
    erver object, ASP 0177 (0×800401F3)
    Invalid class string
    /com/index.asp, line 10

    Marcos de Sousa

  2. Are you able to debug the dll you create in this example?

  3. Hi,

    This is excellent help.
    Still a question…Is it necessary to put a assembly in GAC?

  4. The example works fine, Thanks

    • This doesn’t appear to work in Vista Business. I get a :

      Microsoft VBScript runtime error ‘800a01ad’

      ActiveX component can’t create object

      depends.exe suggests that this is because gpsvc.dll can’t be loaded, but there appears to be no more information on this anywhere. Any help greatly appreciated.

  5. This doesn’t appear to work in Vista Business. I get a :

    Microsoft VBScript runtime error ‘800a01ad’

    ActiveX component can’t create object

    depends.exe suggests that this is because gpsvc.dll can’t be loaded, but there appears to be no more information on this anywhere. Any help greatly appreciated.


Leave a response

Your response:

Categories