Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

VB .NET: regasm.exe and VB .NET Assembly

I have a VB .NET Assembly (.DLL) that I want to register as a COM object using regasm.exe.

I have a server that has the .NET Framework installed.  But when I run regasm.exe it says:

'REGASM' is not recognized as an internal or external command, operable program or batch file.

Is this a path issue, or something else?
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

My goal here is to allow VBScript (inside an ASP page) to call a funciton in my .DLL
Here is the code for my simple DLL:



Imports System.Runtime.InteropServices

<ComVisible(True)> Public Class SecurityCheckPoint
    Private strUserNameEntered
    Public Sub New()
        sbSetNetworkUserName()
    End Sub
    Private Sub sbSetNetworkUserName()
        strUserNameEntered = System.Environment.UserName
    End Sub

    <ComVisible(True)> Public Function fnReturnNetworkUserName() As String
        fnReturnNetworkUserName = strUserNameEntered
    End Function
End Class
Avatar of bgungor
bgungor

First of all, you realize that if you make your ASP page an ASPX page, that you can call into your component without using a COM Callable Wrapper?  Of course, if your ASP page is really big (meaning you want to do absolutely no conversion), then you can use regasm.exe.

The easiest way to use Regasm.exe is to open the Visual Studio .NET Command Prompt located in Start->All Programs->Microsoft Visual Studio .NET->Visual Studio .NET Tools.

Bg
Regasm.exe can also be located in:

C:\Windows\Microsoft .NET\Framework\v1.0.3705

Remember that if you have installed multiple versions of the framework, that there could be different versions in the Framework directory (such as the new 1.1 beta).  In this case, it is still safer to use the VS.NET Command Prompt.

Bg
An ASPX page?  Is that available thru .NET?
Yes, it is ASP.NET.  You can take an ASP page, and add some extra code to make it ASP.NET processable.  In fact, you can code your entire ASP.NET page in VB.NET! (or C#) :)

Bg
To start, try creating a VB.NET Web Application.  That will show you what I am talking about.  In the designer, drop a control on the page, then click on the HTML button at the bottom of the designer.  You will see all of the code that was generated for you.  Don't let that intimidate you, though, because you don't have to convert your page completely to ASP.NET to get the ability to call into your .NET component.

Bg
Found out that we need to do the regasm.exe thing because we need to support legacy ASP pages (no ASP .NET).
In that case, either copy regasm from a computer that has the .NET framework installed, or install the framework onto your server, then run it from the .NET command prompt.

If you still have trouble, let me know.

Bg
Okay.

Yeah, so far this has not gone well...I need to do a little more research on this and I'll get back to you.

Tom
Do I HAVE to have my Assemblies STRONGLY named?  I have been avoiding this.  It is not a concept I feel like I have a good grasp on.
According to the documentation, if you want to register your assembly as COM callable (using the regasm utility), it must be installed into the Global Assembly Cache.  If you do not want to use the GAC, then you must use the CodeBase option on the regasm utility to create the necessary registry entries, but the assembly must be strong named.

For simplicity, I suggest you use the GAC for your COM callable objects.  Strong names are not difficult to implement, but they do require all dependencies to also have strong names, which can become burdensome in larger projects.  If this is a product you are building, I STRONGLY (no pun intended) suggest using strong names, as they have additional features appropriate for a packaged application.

Bg
This product will only be deployed internally, atleast that was the intent.

We are not a Software Development house, meaning, I typically do not deploy what we write.  I am an "Internal Business Systems" type developer.  The stuff I write is deployed internally on our file server and used by Management and other co-workers.
typo:

We are not a Software Development house, meaning, I typically do not deploy what we write.

should be:

We are not a Software Development house, meaning, I typically do not deploy externally what I develop.
I am pretty much the sole Applications developer where I work.  We're a small company.  Our IT Staff consists of:

1 Applications Developer (me)
1 DBA (he sits across from me)
1 Network Administrator
1 Help Desk guy
1 Business Analyst (to gather requirements, etc.)

1 IT Manager (who doubles as the Web Developer.  He wears several hats)

This has nothing to do with the topic at hand, just an interesting tidbit, and some insight into the culture I am writing software in right now.  :)
I can appreciate that.  On my early projects, I was:

1/6 Applications Developer
1/6 DBA
1/6 Network Administrator
1/6 Help Desk guy
1/6 Business Analyst (to gather requirements, etc.)
and
1/6 IT Manager (who doubled as the Web Developer.  I used to wear several hats.)

:)

Bg
LOL!!!  Nice to know someone sympathizes.
Bg:

I need some additional help on this.  I think I need someone to walk me through this step by step by step, as in, first, do this, then do this.  I don't understand how to make .DLL's strongly named, or what the #@$@#$ is the GAC and why do I care about it?

I want to prove to my boss that he can use the .DLL's I write in VB .NET from ASP (note:  this is not ASPX, just ASP)
ASKER CERTIFIED SOLUTION
Avatar of bgungor
bgungor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bg:

In Step 2 above, I am not sure how to construct my relative path.

How can I tell if the relative path I provide is incorrect?  Will the system tell me?

Tom
The main .EXE, Inventory, also has an AssemblyInfo file.

Should the .EXE be strongly named as well?
Okay, I got that figured out.

On one of my Assemblies I get an error message:

Unable to emit assembly: Referenced assembly 'Interop.VBIDE' does not have a strong name

I think VBIDE.dll is something I added so I could work with MS Office.
Yeah, I've got this one Assembly that uses MS Office, so I have included a bunch of .DLL's for MS Excel that are legacy and are not strongly named.
UPDATE:

I followed all the way through to Step 7 okay.

The Framework is installed but the command prompt does not recognize gacutil as a valid program to run.
Make sure you are in

C:\Windows\Microsoft .NET\Framework\v1.0.3705 (or whatever version of the Framework you are running)

before trying to run gacutil or regasm.  You may want to use Explorer to get the path from the address bar, it is very picky.

If you can "dir gac*.exe", you are in the right place.

Bg
Yeah...it did not find gacutil on the computer.

Are the command line utilities like gacutil and regasm a separate install?

The Framework has definitely been installed...I was able to navigate to the folder you said (it was indeed C:\Windows\Microsoft .NET\Framework\v1.0.3705 just like you said) but the gacutil command was not recognized.

Tom
Bg:

UPDATE:

Okay, we got the gacutil and regasm utilities up and running.  I guess we installed the Framework but not the SDK.

Anyway, I have now made it up through step 8.

What I need is a SAMPLE .ASP page (preferrably not .NET .ASP) that can call the function in my Assembly:

fnReturnNetworkUserName( )


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Public Class SecurityCheckPoint
    Private strUserNameEntered

    Private strConnection As String

    Private oConString As New ConString.ConString()

    Public Sub New()
        strConnection = oConString.ConStringSetting
        sbSetNetworkUserName()
    End Sub

    Private Sub sbSetNetworkUserName()
        strUserNameEntered = System.Environment.UserName
    End Sub

    Public Function fnReturnNetworkUserName() As String
        fnReturnNetworkUserName = strUserNameEntered
    End Function
End Class
That is odd.  The gacutil and regasm utilities should be in the redistributable without having to install the framework.  Since you say you didn't find them there, I'll bet if you just copied those two files, instead of installing the entire framework, it would work.  I heard something about this issue somewhere.... oh well.

TEST.ASP -- Copy text below

<%
Response.Write "The username is: "
dim myNetClass
set myNetClass = CreateObject("YourAssemblyName.SecurityCheckPoint")
Response.Write myNetClass.fnReturnNetworkUserName()
if err.Number <> 0 then
   Response.Write err.Message  <- I forget if this will work
end if
%>

-- Copy text above
I ran this in FrontPage on my local machine and it did nothing.
Can you be more specific?

1) Ran it, nothing came out in page.
Most likely, your configuration is wrong, you should minimally get "The username is:".  Make sure you named the file something.asp.  I don't use FrontPage. Just create a virtual directory on your local IIS (myweb), put the file in there, open IE, and type the address http://localhost/myweb/something.asp.

2) Ran it got an error.
What error?

3) If your .NET CCW is wrong, you will get Cannot create object when it attempts to CreateObject.

Bg
Bg:

Thanks for the reply back.

I probably won't be able to look at this again until Monday.  I haven't a clue about how IIS works, but I think it is installed on my local machine.

Tom
I didn't even get "The username is:" so something is definitely not working.
UPDATE:

In the middle of re-installing VS .NET again, but this time I formatted my hard drive and reinstalled Windows 2000 first.
bgungor:

Thanks for your help on this.

Tom