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 2 2022
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 )
RunCodeInOtherA ssembly();
}
private void RunCodeInOtherA ssemly()
{
...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
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 )
RunCodeInOtherA ssembly();
}
private void RunCodeInOtherA ssemly()
{
...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.dl l, 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 that I can handle to go
through my assembly and invoke the static initializer on each relevant
class. This way, everything that needs to be...
|
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 valid until you called "DestroyIcon()". If you didn't, you had a leak.
In C#, I need to load icons from unmanaged programs (.exe, dll) at run time...
|
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 believe that this has
to do with unreleased form component events or event handlers.
I'm comparatively new to .net and windows forms, in the sense that...
|
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 ReadElementBodyAsXml the code works,
but is less efficent. ReadElementBodyAsXml is required by my application
with .Net Framework 1.1.
The code...
|
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!
| |
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
|
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 a page is loaded (where the page in
question makes use of the 3rd party assembly)? Or are all assemblies
referenced by the Web app automatically...
|
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 be relevant.
On my development machine I build the exe and dll and run the exe which has
a reference to the dll. At some point it uses featured in...
|
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 in my C++ routine:
ICLRRuntimeHost* Clr = NULL;
HMODULE hMsCorEE = LoadLibraryA("mscoree.dll");
PROC_CorBindToRuntime* ...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |