Instantiate .net assembly as com from ASP

Started by dhilipkumar, Dec 01, 2008, 07:30 PM

Previous topic - Next topic

dhilipkumar



One of the 3rd party ASP pages is customizable, but again, cannot be changed to .net (that would entail migrating global includes that are used on other asp pages as well). Yet I need to incorporate into that ASP some functionality provided by my asp.net web app. Specifically, I need a way to call .net methods from an asp page.

Now some research gave me the following strategy.
1) Create a .net assembly that contains a class that basically wrapped method calls to the web app assembly and compile it.
2) use regasm to write the appropriate class data to the registry, so it can be called as a COM object.
3) from the ASP page use the following code:
set testobject=server.CreateObject("ogwebComLibrary.testObject")
response.Write (testobject.getText())

Now, the response I kept getting when I viewed the ASP page was "object not set to instance" on the 2nd line: response.write(testObject.getText()).

So a bit more research turned up another way to do this.

1) Create a strong named key and apply it to that assembly. This was more complicated because all other assemples (like those associated with the webapp and the MS Data application block) also needed to be compiled with an snk.
2) use gacutil to register it in the global assembly cache
3) create object from ASP page.

Same error message.

On both occassions, I checked the registry and can see the registry keys pointing to the .net object.

Looking at the error message more closely, I can see that the ASP is not having a problem SEEING the .net object. It is having a problem instanciating it. Yet the object simple looks like this:
Code (abbreviated):

namespace ogwebComLibrary
{

public class testObject{


public testObject(){
}

public string getText(){
}
}
}
The object simply sends a processed ASP.NET page (with a single label whose text is set to "label") to an ASP page, stripping out all the html dealing with body, form, viewstate, etc. It will also handle ASP pages. Just a little test. It will really wrap calls to another assembly once I can be sure ASP can call it's methods.

And an ASP.NET page instanciates it fine. So why won't ASP create the object? It must be seeing the class in the registry (and GAC, for that matter) or I'd get a "class not found"-like exception on the "server.createobject()" line.

I tried using regsvr32.exe, no luck.

VS settings are "use com interop services".

the following lines occur just before the class declaration to enable late binding (for ASP).

[ProgId("ogwebComLibrary.testObject")]
[ClassInterface(ClassInterfaceType.AutoDual)]