473,382 Members | 1,302 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,382 software developers and data experts.

Dynamic Assembly Loading

Does anyone know how to dynamically load an assembly from a location other
that the working directory by using Assembly load method.
It is important to use the specific method because is the method used by CLR
to enforce version and security checking.

I have try by changing the appdomain APPBASE property but is not working and
i am wondering weather I am doing something wrong.

The code I use is the following

AppDomain currentDomain = AppDomain.CurrentDomain;

currentDomain.SetupInformation.ApplicationBase = "Location of hte assembly
to be loaded";

currentDomain.Load("AssemblyName;");

Thanks in advance
Nov 16 '05 #1
2 20868
Assembly.Load(fullpath)

the problem is that the assembly you load must have its dependancies either
in your path/gac/etc.

example ... this loads assemblies not in app path.

public void LoadPluginDirectory(string _Path) {
try {
string [] Files = System.IO.Directory.GetFiles(_Path) ;
foreach (string CurrentFile in Files) {
try {
this.LoadAssembly(CurrentFile) ;
}
catch (Exception Ex) {
throw new System.Exception("Unable to load " + CurrentFile, Ex) ;
}
}
}
catch (Exception Ex) {
throw new System.Exception("Unable to get files from directory\n" +
Ex.Message, Ex) ;
}
}

"Stelios" <st************@avantisworld.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Does anyone know how to dynamically load an assembly from a location other
that the working directory by using Assembly load method.
It is important to use the specific method because is the method used by CLR to enforce version and security checking.

I have try by changing the appdomain APPBASE property but is not working and i am wondering weather I am doing something wrong.

The code I use is the following

AppDomain currentDomain = AppDomain.CurrentDomain;

currentDomain.SetupInformation.ApplicationBase = "Location of hte assembly
to be loaded";

currentDomain.Load("AssemblyName;");

Thanks in advance

Nov 16 '05 #2
There are several problems here. First, you cannot change the appbase of an
appdomain after it has been created. You must specify it as part of the
configuration before creating a new one, which wont help you i the default
appdomain.

If the assembly you want to load is in a directory beneath the current
appbase then you can add its relative path using the
AppendPrivatePath(relativePath), and then use Assembly.Load - the runtime
will probe the subdirectories for you. This is the best/easiest way to
handle it.

If the assembly is located somewhere other then beneath the appbase then you
will have to manually load the assembly using LoadFrom, LoadFile, or some
other Loadxxx variant. You will probably also need to hook the
AssemblyResolve event of the appdomain to resolve references made to types
with the assembly as the program executes. The downside of using any of the
Loadxxx APIs is that assemblies loaded using them do not get added to the
context the runtime uses to automatically resolve references.
"Stelios" <st************@avantisworld.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Does anyone know how to dynamically load an assembly from a location other
that the working directory by using Assembly load method.
It is important to use the specific method because is the method used by CLR to enforce version and security checking.

I have try by changing the appdomain APPBASE property but is not working and i am wondering weather I am doing something wrong.

The code I use is the following

AppDomain currentDomain = AppDomain.CurrentDomain;

currentDomain.SetupInformation.ApplicationBase = "Location of hte assembly
to be loaded";

currentDomain.Load("AssemblyName;");

Thanks in advance

Nov 16 '05 #3

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

Similar topics

0
by: Parag Joshi | last post by:
hi, I am facing a wierd problem with dyanamic class loading. I have a namespace called ETS.DAO which contains my Data Access Object classes. All these classes implement a common interface which...
9
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...
0
by: Thomas W. Brown | last post by:
I have a C# library that dynamically creates a in-memory assembly and creates instances of the objects therein. From .NET applications, this works perfectly well. However, when I wrap this...
2
by: Matt | last post by:
I'm hoping someone can steer me in the right direction to try to do the following: I am developing an application where we receive files from customers. Right now we receive a variety of...
3
by: dhnriverside | last post by:
Hi guys I'm writing a console app in C# for which i want to enable the user to have several "plug-ins". The app has a switch to set the plug-in to use, and at runtime the required dll is loaded...
4
by: Barry Kelly | last post by:
I'm designing an application framework which will, amongst other things, live in an assembly hosted in the ASP.NET worker process, servicing webservice requests. Here's the scenario: APPFX is...
4
by: BrianS | last post by:
What is the best strategy for dynamic loading private assemblies in asp.net? I understand, and have confirmed, that any dll placed in the app's /bin dir will get loaded on startup. This is not...
0
by: Stefan Rosenthal | last post by:
Hi all, I've an OL-Style App loading MDIChild-Windows (Panes) on demand dynamicaly at runtime. Loading the Forms works fine but establishing an EventHandler (to receive information from the...
8
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
1
by: sutch | last post by:
I have created a DDE( Dynamic-Data Exchange) Client (Console) application to interact with a legacy DDE Server. This client is working perfectly I am asked to develop same functionality in a...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.