473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

When exactly a C# assembly gets loaded by managed C++

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
Mar 26 '07 #1
2 2002
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
Mar 28 '07 #2
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
Mar 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Outshined | last post by:
I have a class library where just about every class uses its static initializer to register with a central registry object in the same assembly. I am hoping for some sort of Assembly.Load event...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
13
by: Rick | last post by:
The following code will enter an infinate loop when in ReadChars. I can only make it happen when reading a Stream and with this particular XML. If I use the ReadInnerXml call rather than my own...
1
by: GoogleNewsReaderMan | last post by:
Is there a way for me to know from within a given assembly when it gets loaded? If so, how can this be done? Thanks in advance!
1
by: Chen Zhuo | last post by:
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
2
by: Smithers | last post by:
My ASP.NET Web app uses a few 3rd party assemblies. Just wondering when those are loaded into the Web app's AppDomain - and for how long do they stay loaded. Is an assembly loaded the first time...
8
by: Joe Withawk | last post by:
I have a solution consisting of a c# project as win application and a c++ project as classlibrary. Both are .net 2.0 The classlibrary handles some loading of quicktime movies, but that should not...
0
by: creo | last post by:
OS: Windows XP (32 bit) NET: .Net 2.0 runtime DevEnv: VS 2008 C++ and C# I am attempting to use an unmanaged C++ library to load a managed C# assembly and hand off control. I have the following...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.