Re: When exactly a C# assembly gets loaded by managed C++
- From: Chen Zhuo <chenzhuo914@xxxxxxxxxxx>
- Date: Thu, 29 Mar 2007 10:21:51 +0800
Hi KierenH,
Thanks for your reply, but here it still tries to load the assembly even when I factor the code so that the calling into the assembly is in another method that never gets executed.
The assembly loading behavior we are seeing here is that the assembly loading is at source code file level. Whenever calling an API in the managed cpp file that has "#using MyCSharp.dll", it tries to load MyCSharp.dll immediately, regardless of whether the invoked API really needs MyCSharp.dll.
Could you find any official documentation that clearly states the .NET assembly loading behavior from managed C++? We searched through the web but didn't find much useful info.
Thanks a lot!
Best regards,
Chen Zhuo
KierenH wrote:
I think it's at the method level (I'm sure someone can give a much better explanation), put your call into another assembly in another method. I remember seeing code like this in a CLR Inside-Out article about performance, the scenario they used was for calling code in an exception handler that hardly ever runs (hence, don't want to load the dll most of the time)..
class Test
{
public static void MyFunc()
{
if ( false )
RunCodeInOtherAssembly();
}
private void RunCodeInOtherAssemly()
{
...call into MyCSharp.dll;
}
}
Cheers
Kieren
"Chen Zhuo" wrote:
Hi all experts,
We are having a problem with the exact time when a C# dll gets loaded in
managed C++. The scenario is like:
In managed.cpp:
#using MyCSharp.dll
class Test
{
static void func()
{
if (false)
{
call into MyCSharp.dll;
...
}
}
}
The situation is: when the outside caller calls Test::func(), the
MyCSharp.dll is NOT there (due to some installer constraint). By right,
since the if condition is always a false, we expect no problem for
running Test::func() because we don't actually use anything in
MyCSharpt.dll, however the OS still tries to load MyCSharp.dll at
runtime, and throws exception since the dll cannot be found.
So our questions are:
1. In this case, when is the exact time that the dll gets loaded? Are
there any official document for this assembly loading behavior?
2. Is there any way to make it work at runtime without removing the call
into MyCSharp.dll (we want to keep the code there but it will never get
executed during runtime)?
Your help is greatly appreciated.
Best regards,
Chen Zhuo
- References:
- When exactly a C# assembly gets loaded by managed C++
- From: Chen Zhuo
- RE: When exactly a C# assembly gets loaded by managed C++
- From: KierenH
- When exactly a C# assembly gets loaded by managed C++
- Prev by Date: Re: Shared folders
- Next by Date: Re: Auto-detect internet connection
- Previous by thread: RE: When exactly a C# assembly gets loaded by managed C++
- Next by thread: RE: validateRequest and foreign characters
- Index(es):
Relevant Pages
|