473,503 Members | 10,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2015
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
4794
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
3713
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
10016
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
3217
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
1376
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
349
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
1802
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
3728
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
1691
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
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.