Hello,
I'm trying to load an assembly dynamically using an app domain. This
is a proof-of-concept for a larger project, so please excuse the lame
class names.
TestLib is the dll where all the dynamic loading code will go. The
assemblies being dynamically loaded do not contain any code. They are
resource-only assemblies. I have succeeded in dynamically loading them
within the same AppDomain as the main application (a Winforms EXE that
references TestLib, but TestLib was the one doing the loading).
However, I'm stumped when trying to load them into a separate
AppDomain.
I have a class called Product that represents each dynamically loaded
plugin. I also have a generic class that I have created called
AssemblyWrapper . AssemblyWrapper has a property called
AssemblyFileNam e that is a string reference to an assembly's location
within the file system. AssemblyWrapper has a LoadAssembly method that
simply calls Assembly.Load with the path specified in Assembly file
name. Both classes are members of TestLib. Here is a segment of code
that attempts to load the assembly dynamically into the AppDomain:
public void LoadTestSet(str ing contentPath)
{
DirectoryInfo di = new DirectoryInfo(c ontentPath);
Assembly CurrentAssembly = Assembly.GetExe cutingAssembly( );
AppDomainSetup setup = new AppDomainSetup( );
setup.Applicati onBase = AppDomain.Curre ntDomain.BaseDi rectory;
setup.PrivateBi nPath = di.Name;
setup.Applicati onName = this.productID;
this.ad = AppDomain.Creat eDomain(this.pr oductID, null, setup);
this.aw = (AssemblyWrappe r)ad.CreateInst anceFromAndUnwr ap("TestLib"
, "TestLib.Assemb lyWrapper");
string filePath = contentPath + this.File;
aw.AssemblyPath = filePath;
aw.LoadAssembly ();
//Do some other stuff - it fails before this point.
}
This code blows up on the ad.CreateInstan ceFromAndUnwrap call. It says
it can't find TestLib. This is particularly interesting, as TestLib is
in the GAC. My post-build step calls gacutil /f /i $(targetPath) for
the TestLib dll.
Anybody have any ideas?
Thanks,
Will Gant 2 3110
Arrgh. I'm such a lamer. I changed the code so as to call
Assembly.GetExe cutingAssembly( ).Location to get the name of the TestLib
assembly in a way that allowed the resolver to work. Then, all I had to do
was make my AssemblyWrapper inherit from MarshalByRefObj ect so that it could
be serialized. It figures that I would find the answer within 5 minutes of
posting a question....
"Foehammer" wrote: Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names.
TestLib is the dll where all the dynamic loading code will go. The assemblies being dynamically loaded do not contain any code. They are resource-only assemblies. I have succeeded in dynamically loading them within the same AppDomain as the main application (a Winforms EXE that references TestLib, but TestLib was the one doing the loading). However, I'm stumped when trying to load them into a separate AppDomain.
I have a class called Product that represents each dynamically loaded plugin. I also have a generic class that I have created called AssemblyWrapper . AssemblyWrapper has a property called AssemblyFileNam e that is a string reference to an assembly's location within the file system. AssemblyWrapper has a LoadAssembly method that simply calls Assembly.Load with the path specified in Assembly file name. Both classes are members of TestLib. Here is a segment of code that attempts to load the assembly dynamically into the AppDomain:
public void LoadTestSet(str ing contentPath) { DirectoryInfo di = new DirectoryInfo(c ontentPath); Assembly CurrentAssembly = Assembly.GetExe cutingAssembly( ); AppDomainSetup setup = new AppDomainSetup( ); setup.Applicati onBase = AppDomain.Curre ntDomain.BaseDi rectory; setup.PrivateBi nPath = di.Name; setup.Applicati onName = this.productID; this.ad = AppDomain.Creat eDomain(this.pr oductID, null, setup); this.aw = (AssemblyWrappe r)ad.CreateInst anceFromAndUnwr ap("TestLib" , "TestLib.Assemb lyWrapper");
string filePath = contentPath + this.File; aw.AssemblyPath = filePath; aw.LoadAssembly ();
//Do some other stuff - it fails before this point. }
This code blows up on the ad.CreateInstan ceFromAndUnwrap call. It says it can't find TestLib. This is particularly interesting, as TestLib is in the GAC. My post-build step calls gacutil /f /i $(targetPath) for the TestLib dll.
Anybody have any ideas?
Thanks, Will Gant
This might answer any other questions you might have: http://www.gotdotnet.com/team/clr/AppdomainFAQ.aspx
"foehammer" <fo*******@disc ussions.microso ft.com> wrote in message
news:73******** *************** ***********@mic rosoft.com... Arrgh. I'm such a lamer. I changed the code so as to call Assembly.GetExe cutingAssembly( ).Location to get the name of the TestLib assembly in a way that allowed the resolver to work. Then, all I had to do was make my AssemblyWrapper inherit from MarshalByRefObj ect so that it could be serialized. It figures that I would find the answer within 5 minutes of posting a question....
"Foehammer" wrote:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names.
TestLib is the dll where all the dynamic loading code will go. The assemblies being dynamically loaded do not contain any code. They are resource-only assemblies. I have succeeded in dynamically loading them within the same AppDomain as the main application (a Winforms EXE that references TestLib, but TestLib was the one doing the loading). However, I'm stumped when trying to load them into a separate AppDomain.
I have a class called Product that represents each dynamically loaded plugin. I also have a generic class that I have created called AssemblyWrapper . AssemblyWrapper has a property called AssemblyFileNam e that is a string reference to an assembly's location within the file system. AssemblyWrapper has a LoadAssembly method that simply calls Assembly.Load with the path specified in Assembly file name. Both classes are members of TestLib. Here is a segment of code that attempts to load the assembly dynamically into the AppDomain:
public void LoadTestSet(str ing contentPath) { DirectoryInfo di = new DirectoryInfo(c ontentPath); Assembly CurrentAssembly = Assembly.GetExe cutingAssembly( ); AppDomainSetup setup = new AppDomainSetup( ); setup.Applicati onBase = AppDomain.Curre ntDomain.BaseDi rectory; setup.PrivateBi nPath = di.Name; setup.Applicati onName = this.productID; this.ad = AppDomain.Creat eDomain(this.pr oductID, null, setup); this.aw = (AssemblyWrappe r)ad.CreateInst anceFromAndUnwr ap("TestLib" , "TestLib.Assemb lyWrapper");
string filePath = contentPath + this.File; aw.AssemblyPath = filePath; aw.LoadAssembly ();
//Do some other stuff - it fails before this point. }
This code blows up on the ad.CreateInstan ceFromAndUnwrap call. It says it can't find TestLib. This is particularly interesting, as TestLib is in the GAC. My post-build step calls gacutil /f /i $(targetPath) for the TestLib dll.
Anybody have any ideas?
Thanks, Will Gant 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...
|
by: Ender |
last post by:
I have an application that I would like third party developers to be
able to create Plug-ins that will be dynamically loaded into our
application to extend functionality.
I have utilized the "Let Users Add Functionality to Your .NET
Applications with Macros and Plug-Ins" article at MSDN for the dynamic
loading of DLLs
...
|
by: JonS. |
last post by:
Hi,
I posted this article (
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.csharp&mid=0ee9781a-78f7-4398-a0ef-eeb195eccaea&sloc=en-us
) last week, and have yet to receive any replies. If someone could please
give me further information I would greatly appreciate it.
Sincerely,
Jon
|
by: Pete Davis |
last post by:
I'm confused about what precisely the limitations are on loading plugins in
separate app domains. In all my previous apps that supported plugins, I've
loaded them into the same domain as the app, but I've just started playing
around with separate AppDomains and I'm finding that I'm not having problems
where I expected I would, so maybe someone...
|
by: Foehammer |
last post by:
Hello,
I'm trying to load an assembly dynamically using an app domain. This
is a proof-of-concept for a larger project, so please excuse the lame
class names.
TestLib is the dll where all the dynamic loading code will go. The
assemblies being dynamically loaded do not contain any code. They are
resource-only assemblies. I have succeeded in...
| |
by: Andrew Ducker |
last post by:
I'm trying to load an assembly into a temporary AppDomain rather than
my main AppDomain, so that it can be unloaded later on. However, it's
also loading into my main AppDomain at the same time.
My code is:
AppDomain a = AppDomain.CreateDomain("TestDomain");
a.Load("AppDomainTestAssembly");
and in the Console window I get the following...
|
by: jnick |
last post by:
I have the predicament of having to load several assemblies on the fly and
when I do so, I get an exception stating that one of the referenced
assemblies cannot be found. Is there any way to recurse into an assembly to
discover the referenced assemblies without actually loading the root assembly
where I start the load?
For example:
...
|
by: Jeff |
last post by:
Hi
I'm trying to achieve a scenario where I have c# files that are compiled
dynamically, the assemblies are then loaded in a different AppDomain, I call
a simple method from the object, and then unload the AppDomain to release
the lock on the assemly files (so to I can compile the code again if it has
been modified). However, I've...
|
by: =?Windows-1252?Q?Tor_B=E5dshaug?= |
last post by:
BlankHi,
I am having trouble loading assemblies from the database in my ASP.NET app.
I have a default.aspx in my app that is served from a database via a custom virtual path provider. This works fine, until this
default.aspx uses code in a dependent assembly (say CustomAssembly). Then ASP.NET cannot find the class "CustomAssembly.MyClass" and...
|
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: 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...
|
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: 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: 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
| |