473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to dynamically load assembly w/ dependencies??

I'm trying to access my application files for a plug-in I'm building for a
third party application.

I have an assembly with several dependency assemblies. The dependency
assemblies are in the same directory as the assembly.

d:\dev\cs\MyApp\bin\Release\MyApp.dll
d:\dev\cs\MyApp\bin\Release\Dependency1.dll
d:\dev\cs\MyApp\bin\Release\Dependency2.dll

Note that all DLLs are strongly named with a keyfile. Also note that the
project MyApp.dll references Dependency1.dll, et al, by the Project for
debugging.

I am trying to load MyApp.dll dynamically from my plug-in that runs in the
third party application.

Assembly pbAssembly =
Assembly.LoadFile(GetRegSetting("Settings", "AppPath",
AppDomain.CurrentDomain.BaseDirectory)
+ "\\MyApp.dll"); // this is something I store manually

This works fine so far. When I attempt to call the properties/methods on my
DLL, I get the error message:

"File or assembly name Dependency1.dll, or one of its dependencies, was
not found."

This makes sense because the assembly loader checks for the dependencies
from the current application's base directory and the GAC and the CLR
runtime (not in that order), and nowhere else.

I don't want to use the GAC for my application. I would rather manually
reference each file, but even then I don't know how to do that other than
loading the Assembly file and disposing it (does that work? can I do that?
would it be sufficient?).

So my question is: How can I modify or append to the PrivateBinPath for the
current AppDomain?

Thanks for any help,
Jon
Nov 15 '05 #1
1 20984
Hi Jon,

Subscribe to the current AppDomain's AssemblyResolve event and load the
referenced assemblies manually since you know their location on disk.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I'm trying to access my application files for a plug-in I'm building for a
third party application.

I have an assembly with several dependency assemblies. The dependency
assemblies are in the same directory as the assembly.

d:\dev\cs\MyApp\bin\Release\MyApp.dll
d:\dev\cs\MyApp\bin\Release\Dependency1.dll
d:\dev\cs\MyApp\bin\Release\Dependency2.dll

Note that all DLLs are strongly named with a keyfile. Also note that the
project MyApp.dll references Dependency1.dll, et al, by the Project for
debugging.

I am trying to load MyApp.dll dynamically from my plug-in that runs in the
third party application.

Assembly pbAssembly =
Assembly.LoadFile(GetRegSetting("Settings", "AppPath",
AppDomain.CurrentDomain.BaseDirectory)
+ "\\MyApp.dll"); // this is something I store manually

This works fine so far. When I attempt to call the properties/methods on my DLL, I get the error message:

"File or assembly name Dependency1.dll, or one of its dependencies, was not found."

This makes sense because the assembly loader checks for the dependencies
from the current application's base directory and the GAC and the CLR
runtime (not in that order), and nowhere else.

I don't want to use the GAC for my application. I would rather manually
reference each file, but even then I don't know how to do that other than
loading the Assembly file and disposing it (does that work? can I do that?
would it be sufficient?).

So my question is: How can I modify or append to the PrivateBinPath for the current AppDomain?

Thanks for any help,
Jon


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Boni | last post by:
Dear Sirs, If I dynamically load assembly into the memory by Load(byte) how long do I have to preserve the array valid? Can it be destructed just after the load call? Thanks in advance, Boni
1
by: M. Fitzgerald | last post by:
Our migration from ASP to ASP.NET will be a slow one. In themeantime, I have constructed a .NET assembly and registered itas a COM object for use in out classic ASP pages. One of thethings this...
1
by: Nancy Sui | last post by:
I am trying to dynamically load a dll which specifies different rules for evalution with the following code. DataRow dr = ds.Tables.Rows; string fileName = Convert.ToString(dr); assemblyInstance...
0
by: Robin | last post by:
Hi all, I am trying to dynamically load a class, and I'm having trouble getting past the Assembly.LoadFrom part (or at least I think so) Error: The located assembly's manifest definition with...
3
by: dercon | last post by:
I'm attempting to dynamically load an assembly from a windows service. However, i'm having problems when the service runs... he is the line of code that causes the error: dim loAssembly as...
6
by: Dan Dorey | last post by:
I actually have two questions here, but I'll start by giving an outline of what I'm trying to do. I'm building an app with a simple plugin architecture (all in the same app domain). I have each...
2
by: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
0
by: =?Utf-8?B?Y211cmFsaQ==?= | last post by:
I am serializing/deserializing a class (Class1) using the XmlSerializer object in the System.Xml.Serialization namespace in .Net 2.0. Class1 has some strings and ints and two lists of other simple...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.