Hey all,
I'm working on this project where I'm dynamically loading an assembly.
Basically what I want is that I can just replace my old dll file with a new
one without having to do anything else.
So to test this, I did the following: I temporarily tested it by saving my
dll file in C:\, so let's say I have C:\dynamic.dll.
I have created a winforms application with a simple button that calls the
method with Assembly.Load, which you can see here (notice a lot of debug
statement to try and find the problem):
public MyClass getClass(Domain domain)
{
AssemblyName assemblyName = new AssemblyName();
Assembly classAssembly = null;
try
{
assemblyName.Co deBase = @"C:\dynamic.dl l";
System.Diagnost ics.Debug.Write Line("Codebase for dynamic dll set to: "
+ assemblyName.Co deBase);
classAssembly = Assembly.Load(a ssemblyName);
System.Diagnost ics.Debug.Write Line("Loaded dynamic.dll, returning
instance...");
return (MyClass)classA ssembly .CreateInstance ("MyClass2", false,
System.Reflecti on.BindingFlags .CreateInstance , null, null, null, new
Object[]{domain});
}
catch(Exception ex) {
System.Diagnost ics.Debug.Write Line("Exception : " + ex.Message); }
finally {
classAssembly = null; assemblyName =
null;System.Dia gnostics.Debug. WriteLine("Clea ning up"); }
return null;
}
So, now comes the problem. When I test this the first time, all is well. All
debug statements are printed and my output furthermore shows ''test.exe':
Loaded 'c:\dynamic.dll ', Symbols loaded.' to show it actually loaded the
assembly.
However when I rename my dynamic.dll to bogus.dll and click the button again
(without closing the application) it won't throw an exception 'dynamic.dll
not found' or something, which I was expecting. It does show all debug
statements again, but nothing else. I first thought it was still in memory
or something, therefor I added the try-catch-finally block in my getClass
method and set my objects to null (but as I was expecting, that didn't
help).
So, is there more to this then meets the eye? Can I / Do I have to unload
the assembly somehow? Why doesn't it give the error when renaming my dll so
it shouldn't be found?
Thanks! Regards,
Razzie 2 5336
Hey Razzie,
Once you've loaded an assembly to the AppDomain, you cannot unload the
assembly - you have to unload the entire domain.
Therefore, if you need to reload an assembly 'on the fly', you have to use a
dedicated AppDomain. I have gone through all this hell while working on
X-Unity, so if you are stuck with some problem - post it here and hopefully
I notice your message and reply :-)
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx
"Razzie" <ra****@quickne t.nl> wrote in message
news:eT******** ******@tk2msftn gp13.phx.gbl... Hey all,
I'm working on this project where I'm dynamically loading an assembly. Basically what I want is that I can just replace my old dll file with a new one without having to do anything else. So to test this, I did the following: I temporarily tested it by saving my dll file in C:\, so let's say I have C:\dynamic.dll.
I have created a winforms application with a simple button that calls the method with Assembly.Load, which you can see here (notice a lot of debug statement to try and find the problem):
public MyClass getClass(Domain domain) { AssemblyName assemblyName = new AssemblyName(); Assembly classAssembly = null; try { assemblyName.Co deBase = @"C:\dynamic.dl l"; System.Diagnost ics.Debug.Write Line("Codebase for dynamic dll set to: " + assemblyName.Co deBase); classAssembly = Assembly.Load(a ssemblyName); System.Diagnost ics.Debug.Write Line("Loaded dynamic.dll, returning instance..."); return (MyClass)classA ssembly .CreateInstance ("MyClass2", false, System.Reflecti on.BindingFlags .CreateInstance , null, null, null, new Object[]{domain}); } catch(Exception ex) { System.Diagnost ics.Debug.Write Line("Exception : " + ex.Message); } finally { classAssembly = null; assemblyName = null;System.Dia gnostics.Debug. WriteLine("Clea ning up"); } return null; }
So, now comes the problem. When I test this the first time, all is well. All debug statements are printed and my output furthermore shows ''test.exe': Loaded 'c:\dynamic.dll ', Symbols loaded.' to show it actually loaded the assembly.
However when I rename my dynamic.dll to bogus.dll and click the button again (without closing the application) it won't throw an exception 'dynamic.dll not found' or something, which I was expecting. It does show all debug statements again, but nothing else. I first thought it was still in memory or something, therefor I added the try-catch-finally block in my getClass method and set my objects to null (but as I was expecting, that didn't help).
So, is there more to this then meets the eye? Can I / Do I have to unload the assembly somehow? Why doesn't it give the error when renaming my dll so it shouldn't be found?
Thanks! Regards,
Razzie
'This hell'? Lol that sounds like it may be too much work for my project!
Anyway, I'll sure take a look at it as soon as I can. Thanks!
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. Hey Razzie,
Once you've loaded an assembly to the AppDomain, you cannot unload the assembly - you have to unload the entire domain. Therefore, if you need to reload an assembly 'on the fly', you have to use a dedicated AppDomain. I have gone through all this hell while working on X-Unity, so if you are stuck with some problem - post it here and hopefully I notice your message and reply :-)
-- Sincerely, Dmitriy Lapshin [C# / .NET MVP] Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx
"Razzie" <ra****@quickne t.nl> wrote in message news:eT******** ******@tk2msftn gp13.phx.gbl... Hey all,
I'm working on this project where I'm dynamically loading an assembly. Basically what I want is that I can just replace my old dll file with a new one without having to do anything else. So to test this, I did the following: I temporarily tested it by saving my dll file in C:\, so let's say I have C:\dynamic.dll.
I have created a winforms application with a simple button that calls the method with Assembly.Load, which you can see here (notice a lot of debug statement to try and find the problem):
public MyClass getClass(Domain domain) { AssemblyName assemblyName = new AssemblyName(); Assembly classAssembly = null; try { assemblyName.Co deBase = @"C:\dynamic.dl l"; System.Diagnost ics.Debug.Write Line("Codebase for dynamic dll set to: " + assemblyName.Co deBase); classAssembly = Assembly.Load(a ssemblyName); System.Diagnost ics.Debug.Write Line("Loaded dynamic.dll, returning instance..."); return (MyClass)classA ssembly .CreateInstance ("MyClass2", false, System.Reflecti on.BindingFlags .CreateInstance , null, null, null, new Object[]{domain}); } catch(Exception ex) { System.Diagnost ics.Debug.Write Line("Exception : " + ex.Message); } finally { classAssembly = null; assemblyName = null;System.Dia gnostics.Debug. WriteLine("Clea ning up"); } return null; }
So, now comes the problem. When I test this the first time, all is well. All debug statements are printed and my output furthermore shows ''test.exe': Loaded 'c:\dynamic.dll ', Symbols loaded.' to show it actually loaded the assembly.
However when I rename my dynamic.dll to bogus.dll and click the button again (without closing the application) it won't throw an exception 'dynamic.dll not found' or something, which I was expecting. It does show all debug statements again, but nothing else. I first thought it was still in memory or something, therefor I added the try-catch-finally block in my getClass method and set my objects to null (but as I was expecting, that didn't help).
So, is there more to this then meets the eye? Can I / Do I have to unload the assembly somehow? Why doesn't it give the error when renaming my dll so it shouldn't be found?
Thanks! Regards,
Razzie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Krueger |
last post by:
Hi
I'm currently working on a forms designer for a free .NET IDE
(SharpDevelop -> www.icsharpcode.net/OpenSource/SD).
problem:
I try to put 'custom' components (user controls from the current open
project) into the forms designer. The project must be compiled for
making this work. Now after recompile I need to update the user control
with the newly compiled version (maybe something has changed). And THAT
|
by: Luis Pinho |
last post by:
Hi There,
I've got a server that is waiting for requests, these request
correspond to calls to objects that are specified in assemblies stored
in the GAC.
To do this, I use reflection to call the methods.
Now, when I'm trying to optimize the code, I noticed that the
assemblies that are loaded during the reflection call, are never
|
by: Stelios |
last post by:
Does anyone know how to dynamically load an assembly from a location other
that the working directory by using Assembly load method.
It is important to use the specific method because is the method used by CLR
to enforce version and security checking.
I have try by changing the appdomain APPBASE property but is not working and
i am wondering weather I am doing something wrong.
The code I use is the following
|
by: Aashish Patil |
last post by:
Hi,
My code is trying to load an assembly using
Assembly.Load(string assemblyName);
Assume that the current executing assembly is called
Test.dll
The following code works fine
|
by: Nak |
last post by:
Hi there,
Does anyone know how I would get the value of the assembly GUID in code
from within the same application? Thanks in advance.
Nick.
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
| |
by: lgbjr |
last post by:
Hi All,
I am moving some of my MDI Child forms to DLLs. The first 3 forms worked
fine. But the 4th one is causing me some grief! I use the following code to
load a form from a DLL:
Dim asmAssemblyContainingForm As =
.LoadFrom("neiconv.dll")
Dim TypeToLoad As Type =
asmAssemblyContainingForm.GetType("neiconv.Frm_ND")
|
by: Steve |
last post by:
I'm playing with late binding and trying a very simple test to load an
assembly
In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\TestModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>
|
by: Erland |
last post by:
Hi all,
As per my understanding in order to load an assembly using
Assembly.Load() you have to provide fully qualified name of the
assembly you are trying to load e.g.
Assembly
asmb=Assembly.Load("System.Windows.Forms,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089");
In this case i will have to provide the whole big string in
|
by: Ron M. Newman |
last post by:
Hi,
I can load an assembly using the Assembly.Load(....)
However, I'd like dynamic loading of assemblies to be identical to putting
an assembly reference in your VS2005 project. and yes, I know about the
unloading problems. Let's say I don't care for the moment.
If I have an assemlbly file at "c:\\assembly.dll" - how do I load it at
runtime as if it were references in the project at build time? I know
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |