Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / February 2006

Tip: Looking for answers? Try searching our database.

Registering a .NET assembly for COM interop access from an ASP page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zoe Hart - 08 Feb 2006 19:19 GMT
I need to access a .NET assembly from a traditional ASP page. What I've read
in the .NET Framework documentation says I have to do two things:

1) Register the assembly using regasm.exe. I've done that.

2) "After registering an assembly using Regasm.exe, you can install it in
the global assembly cache so that it can be activated from any COM client.
If the assembly is only going to be activated by a single application, you
can place it in that application's directory."

In my case, the assembly will only be accessed from pages in the ASP
website. I've tried dropping the dll in the root folder for the application,
but I still get an error each time I try to instantiate the object in ASP.
The error says "File or assembly name TestNetAssembly, or one of its
dependencies, was not found." I tried putting it in the site bin folder
(it's a hybrid ASP/ASP.NET site, so it has a bin folder) but that didn't
work.

I guess I could fall back on putting it in the global assembly cache, which
is what I've seen other developers do, but it's frustrating because the
above documentation suggests I don't have to and the .NET Framework
documentation about the global assembly cache itself states specifically
that "it is not necessary to install assemblies into the global assembly
cache to make them accessible to COM interop or unmanaged code".

What am I missing? Maybe installation in the GAC is required specifically
for access from ASP?

Thanks,
Zoe
"Peter Huang" [MSFT] - 09 Feb 2006 05:53 GMT
Hi Zoe,

I think you may try to use the regasm /codebase to register the .NET
assembly.
Also because the ASP page is executed in the exe file which is located in
the %systemroot%\system32\inetsrv, the bin directory is the directory which
stored the asp.net code behind page.

So far I think you may try to use the /codebase switch to register the .NET
assemblly.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Zoe Hart [MVP] - 09 Feb 2006 15:14 GMT
Peter,

I'm having trouble making sense of your second paragraph. "Also because the
ASP page is executed in the exe file which is located in the
%systemroot%\system32\inetsrv (I followed you that far; then you lost me),
the bin directory is the directory which stored the asp.net code behind
page." So by "bin directory" do you mean the directory where the process
will be looking for the .net assembly DLL, which is what I'm trying to
figure out?  And why would it have anything to do with where the ASP.NET
code behind file is when the .NET assembly is called from an ASP page, not
an ASP.NET page? I've tried putting the DLL where the .asp code is located,
but that didn't work. Is it possible it needs to be where inetsrv.exe is?

Thanks,
Zoe

> Hi Zoe,
>
[quoted text clipped - 17 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Zoe Hart - 09 Feb 2006 15:50 GMT
I tried putting my .NET assembly DLL in %systemroot%\system32 and that
works.

Zoe

> Peter,
>
[quoted text clipped - 34 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
"Peter Huang" [MSFT] - 10 Feb 2006 03:07 GMT
Hi Zoe,

I am sorry I did not make it more clear.
The bin directory is meanful for the ASP.NET application.
But for ASP, it has a different mechanism. For an ASP page, it is running
at inetinfo.exe(The IIS process), or the dllhost.exe. This depends on how
you config your ASP application. If you config the Application protection
as Low, it will run in the IIS process(inetinfo.exe).
The inetinfo.exe is under the dir below.
c:\WINDOWS\system32\inetsrv
The dllhost.exe is under the dir below.
c:\WINDOWS\system32\inetsrv

When we call COM from ASP page, it is going the way of legacy win32
application.
In a Win32 Process, there will be a Working dir when we create a process.

lpCurrentDirectory
[in] Pointer to a null-terminated string that specifies the full path to
the current directory for the process. The string can also specify a UNC
path.
If this parameter is NULL, the new process will have the same current drive
and directory as the calling process. (This feature is provided primarily
for shells that need to start an application and specify its initial drive
and working directory.)
CreateProcess
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/createprocess.asp

So the IIS process or dllhost will check the lpCurrentDirectory in their
environment block which is a internal structure for a Process.
Because the IIS process or dllhost's default lpCurrentDirectory is
%systemroot%\system32, so it will try to find the COM dll(the .NET assembly
has been registered as a legacy COM) in the dir above.
That is why when you put the dll under the %systemroot%\system32, it will
work.
But this is not recommend, because that dir is mainly used for stored
system dll, it is hard to maintain if you had put many your own dll in that
dir.

BTW: have you tried my suggestion, that use regasm /codebase to register
the .NET dll as COM?
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Zoe Hart [MVP] - 22 Feb 2006 15:59 GMT
I have tried putting my DLL in C:\Windows\System32\InetSrv and the ASP page
fails with Server.CreateObject failed. If I put my DLL in
C:\Windows\System32 it works. I have tried your regasm /codebase suggestion,
but it requires a strongly named assembly and my customer says they've had
problems with ASP pages calling a strongly named assembly, so I have to
decide if I want to go down that path. I don't really understand how the
codebase option is supposed to work. According to the regasm documentation
the codebase option creats a codebase entry in the registry that specifies
the file path for an assembly. How does the regasm /codebase command know
what the filepath should be. Is the the filepath of the DLL that's being
registered?

Zoe

> Hi Zoe,
>
[quoted text clipped - 51 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 23 Feb 2006 04:44 GMT
Hi Zoe,

Yes, in this scenario, we need to put the Assembly into the
C:\Windows\System32 because it is the directory which is the working
directory for the IIS process.
The working directory is the place where the process will check for the dll.

If we call regasm with /codebase, the full path will be registered in the
registry. If we did not specifed the /codebase, only the file name will be
entered into registry.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Zoe Hart [MVP] - 23 Feb 2006 15:56 GMT
Peter,

I realized I was misreading the response from regasm.exe when I tried to
register my unsigned assembly with the /codebase option. I was distracted by
the long warning: "RegAsm : warning RA0000 : Registering an unsigned
assembly with /codebase can cause your assembly to interfere with other
applications that may be installed on the same computer. The /codebase
switch is intended to be used only with signed assemblies. Please give your
assembly a strong name and re-register it." And I missed the "Types
registered successfully" bit that followed.

I'm now using /codebase and things are working well. Thank you for all your
help.

Zoe

> Hi Zoe,
>
[quoted text clipped - 16 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 24 Feb 2006 05:33 GMT
Hi Zoe,

You are welcomed!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.