473,651 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\My App.dll
d:\dev\cs\MyApp \bin\Release\De pendency1.dll
d:\dev\cs\MyApp \bin\Release\De pendency2.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.LoadFi le(GetRegSettin g("Settings", "AppPath",
AppDomain.Curre ntDomain.BaseDi rectory)
+ "\\MyApp.dl l"); // 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 21102
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******** ********@TK2MSF TNGP09.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\My App.dll
d:\dev\cs\MyApp \bin\Release\De pendency1.dll
d:\dev\cs\MyApp \bin\Release\De pendency2.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.LoadFi le(GetRegSettin g("Settings", "AppPath",
AppDomain.Curre ntDomain.BaseDi rectory)
+ "\\MyApp.dl l"); // 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
1656
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
1269
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 particular assembly does is use Reflection todynamically load another assembly (based of course onuser-provided parameters). The original error is in that it could not locate the assembly tobe loaded. I've tried placing the dynamically loaded...
1
1733
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 = Assembly.Load( fileName ); typeInstance = assemblyInstance.GetType( "MSF.Storefront.Rules." + dr.ToString() , true, false); Object parameter = new Object; if (seg == null) parameter = cs;
0
1017
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 name 'MyAssemblyName' does not match the assembly reference. Assembly code: <Assembly: AssemblyKeyFileAttribute("assemblykeys.snk")>
3
3517
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 Assembly = Assembly.LoadFrom("SomeDLL.dll") I have a test windows Form that i use when developing services... this way i can run the service in debug mode. If i run as a windows form, the code executes fine and the assembly loads. However, when i...
6
6874
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 plugin in a separate sub-dir inside a "Plugins" directory. Each plugin consists of at least two DLLs (a controller and a driver). However, most drivers also rely on other external DLLs. In one particular case this dependency is to a C++ DLL...
2
3105
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 dynamically loaded assembly) so far so good (per my code below)... but here is where I'm getting hung up: 3. Call methods of that type (see comments in my code) If the types in the dynamically loaded assembly were in the same namespace
7
10069
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 trouble using a library that creates an instance of a Type that i specified, and it failed the locate the Type during runtime, if i do not reference it during compile time.
0
2476
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 serializable classes (Class2 and Class3) Class1, Class2 and Class3 are defined in an assembly (Assembly1) which is loaded by another assembly (Assembly2). When I statically reference Assembly1 in Assembly2, serialization and deserialization...
0
8347
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8457
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5605
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
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
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.