Groups | Blog | Home
all groups > dotnet interop > march 2005 >

dotnet interop : dllimport and web services



Will
3/14/2005 10:56:50 AM
I have an C#/ASP.Net 1.1 Web Service that has an exposed Web Method
that uses an unmanaged DLL via the DllImport Attribute. Is one copy of
the DLL loaded per call to the Web Method, or does ASP.Net use the same
instance of the DLL for every call to the Web Method? My guess is that
due to the "static" keyword required by the DllImport attribute
indicates that only one copy is used for all requests.

The creator of the DLL has doubts that it is thread-safe, and would
like me to ensure that a new copy of the DLL is loaded with each call
to the web method. Is there a way to force the web service to use a
fresh copy?

The Web Service runs on a Win2k Server PC under IIS 5.

Thanks,
Will.
Will
3/14/2005 1:37:27 PM
Mattias,

Thank you for the reply. I have some follow-up questions that will help
me understand this better.

In native code (C++) for example, it is possible to explicitly load and
unload a DLL. If 2 different native programs load the same dll at the
same time, am I right in assuming that 2 copies of the DLL have been
loaded (1 per process space)? In the ASP.NET/IIS 5 world, am I right in
thinking that aspnet_wp.exe holds in its memory the single instance of
the unmanaged DLL?

[quoted text, click to view]

Ridiculous meaning impossible or ridiculous meaning it would be a
really bad idea? If it's possible, how would one go about doing it? I
[quoted text, click to view]
the unmanaged DLL, who happens in this case to by my boss's boss, so I
want to have a solid answer here to present to him.

Thanks for your time,
Will.
Mattias Sjögren
3/14/2005 9:54:52 PM

[quoted text, click to view]

No, you'll only have a single copy loaded.


[quoted text, click to view]

Yes, but it's not an ASP.NET feature, it's an OS feature.


[quoted text, click to view]

FWIW, you'll only have one copy of a method's code in memory (at least
per app domain), regardless of whether or not the method is static.


[quoted text, click to view]

That would be ridiculous.


[quoted text, click to view]

No. If it isn't thread safe you'll have to synchronize calls to it.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Mattias Sjögren
3/14/2005 11:38:12 PM

[quoted text, click to view]

If possible, only a single copy of the code will be loaded into
physical memory, and it's then mapped into each process' address
space. This is of course to save memory. Consider how memory consuming
it sould be if every process had its own copy of the core system
libraries (such as Kernel32.dll).


[quoted text, click to view]

Yes.


[quoted text, click to view]

I should probably have said "ridiculously memory consuming", meaning
it's a really bad idea. And a weird solution to the threading problem.


[quoted text, click to view]

I don't think it's possible, no.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button