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
AssemblyFileName 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(string contentPath)
{
DirectoryInfo di = new DirectoryInfo(contentPath);
Assembly CurrentAssembly = Assembly.GetExecutingAssembly();
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
setup.PrivateBinPath = di.Name;
setup.ApplicationName = this.productID;
this.ad = AppDomain.CreateDomain(this.productID, null, setup);
this.aw = (AssemblyWrapper)ad.CreateInstanceFromAndUnwrap("T estLib"
, "TestLib.AssemblyWrapper");
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.CreateInstanceFromAndUnwrap 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 2965
Arrgh. I'm such a lamer. I changed the code so as to call
Assembly.GetExecutingAssembly().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 MarshalByRefObject 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 AssemblyFileName 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(string contentPath) { DirectoryInfo di = new DirectoryInfo(contentPath); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; setup.PrivateBinPath = di.Name; setup.ApplicationName = this.productID; this.ad = AppDomain.CreateDomain(this.productID, null, setup); this.aw = (AssemblyWrapper)ad.CreateInstanceFromAndUnwrap("T estLib" , "TestLib.AssemblyWrapper");
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.CreateInstanceFromAndUnwrap 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*******@discussions.microsoft.com> wrote in message
news:73**********************************@microsof t.com... Arrgh. I'm such a lamer. I changed the code so as to call Assembly.GetExecutingAssembly().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 MarshalByRefObject 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 AssemblyFileName 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(string contentPath) { DirectoryInfo di = new DirectoryInfo(contentPath); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; setup.PrivateBinPath = di.Name; setup.ApplicationName = this.productID; this.ad = AppDomain.CreateDomain(this.productID, null, setup); this.aw = (AssemblyWrapper)ad.CreateInstanceFromAndUnwrap("T estLib" , "TestLib.AssemblyWrapper");
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.CreateInstanceFromAndUnwrap 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...
|
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...
|
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...
|
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,...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |