loading assembly

G

Guest

I want to creat a new application domain called 'mydomain' and then load an
assembly named 'myassembly.dll' into the domain. The assembly is in the
folder "C:\Mydata\assembly", which is not the running program folder. I then
want to load the 'MainClass" found in 'myassembly'. I'm having a little
trouble loading because the assembly is not in the program folder.

Any suggestions.
Thanks,
 
M

Michael Nemtsev

Hello RickN,

You can use AppDomainSetup.ApplicationBase to set where are you assemblies
located
like

AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ApplicationBase = @"C:\Mydata\assembly";


R> I want to creat a new application domain called 'mydomain' and then
R> load an assembly named 'myassembly.dll' into the domain. The
R> assembly is in the folder "C:\Mydata\assembly", which is not the
R> running program folder. I then want to load the 'MainClass" found in
R> 'myassembly'. I'm having a little trouble loading because the
R> assembly is not in the program folder.
R>
R> Any suggestions.
R> Thanks,
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
G

Guest

Thanks Michael:
Even with referencing the path in the AppDomainSetup, I still get an error.
The error doesn't seem to be related to the path.
Here is a representation of my code.

AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = @"C:\Mydata\assembly";
AppDomain app = AppDomain.CreateDomain(mydomain, null, info);
//so far so good.
//the next step throws an exception: "Type not resolved for ...--it then
references the calling assembly.
Assembly asm = app.Load("myassembly.dll"); //error w/orw/o
".dll" (myassembly is the assembly I want to load into the app AppDomain, it
is in the "C:\Mydata\assembly" folder.

If I copy the assembly to the local folder the above
app.Load("myassembly.dll") code works.
Any suggestions are appreciated.

Thanks,
Rick
 
M

Michael Nemtsev

Hello RickN,

Check that AppDomainSetup.PrivateBinPath is pointed on the same directory
And try to specify the fully quialified name of you myassembly.dll in the
app.Load


R> Thanks Michael:
R> Even with referencing the path in the AppDomainSetup, I still get an
R> error.
R> The error doesn't seem to be related to the path.
R> Here is a representation of my code.
R> AppDomainSetup info = new AppDomainSetup();
R> info.ApplicationBase = @"C:\Mydata\assembly";
R> AppDomain app = AppDomain.CreateDomain(mydomain,
R> null, info);
R> //so far so good.
R> //the next step throws an exception: "Type not resolved for ...--it
R> then
R> references the calling assembly.
R> Assembly asm = app.Load("myassembly.dll"); //error
R> w/orw/o
R> ".dll" (myassembly is the assembly I want to load into the app
R> AppDomain, it
R> is in the "C:\Mydata\assembly" folder.
R>
R> If I copy the assembly to the local folder the above
R> app.Load("myassembly.dll") code works.
R> Any suggestions are appreciated.
R> Thanks,
R> Rick
R> "Michael Nemtsev" wrote:
R>---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

I set the PrivateBinPath to the same path and tried every variation I can
think of on the Load. I get the same error:
System.RunTime.Serialization.SerializationException
{"Type is not resolved for member ...(plus reference to calling assembly)
(I think my previous statement that it loaded from the local folder was in
error.)

Everything else being the same, if I try to load the same dll into an
assembly (no AppDomain), it works just fine using LoadFrom. However, I need
to be able to unload the assembly, so I need the assembly in the new
AppDomain not the default AppDomain.

Any suggestions are appreciated.
Thanks,
Rick
 
G

Guest

Michael

I've found a solution.
I rebuilt the external dll and modified the class in the dll to inherit from
MarshallByRef. Once I did that, the assembly loaded into the appdomain.

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top