473,395 Members | 1,454 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,395 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 21007
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
tracyyun
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...

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.