473,763 Members | 6,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Loaded Assemblies and Custom ConfigurationSe ction Handlers

I have a Windows Forms application that implements a plug-in architecture
whereby required assemblies are identified and loaded dynamically.

Here are the relevant classes:

A = application = Windows Forms class

B = a singleton hosted within A. B is responsible for dynamically loading
classes X, Y, and Z.

X, Y, and Z = "worker bee" classes that do all of the grunt work of this
application. Each of these classes exists in its own assembly. B loads their
containing assemblies dynamically via reflection:
System.Reflecti on.Assembly.Loa dFile(pathToAss embly).

Being that X, Y, and Z are contained within their respective class
libraries, they cannot have their own .config files. I decided it was okay,
for this particular application, for the App.config file (of A, the
application class) to have custom configuration sections for each of the X,
Y, and Z classes. So X, Y, and Z, if/when loaded, need to read their
respective custom configuration sections from App.config.

Now, to get into the problem area:
I am dynamically loading the assemblies containing X, Y, and Z from
C:\SomeFolder --- and NOT from \bin or a subfolder under \bin

The loading of the assemblies happens just fine, as I am able to specify the
full path to the assemblies via Assembly.LoadFi le(pathToAssemb ly).

So far so good.

Here's where the problem happens:

While X, Y, and Z can read App.config - no problem - the custom
ConfigurationSe ction handler classes, which are also compiled into the
assemblies containing classes X, Y, and Z are INCORRECTLY assumed by the CLR
to exist in assemblies located in or under project A's \bin. I have verified
this through my testing:

Test 1:
If I ensure that the assemblies for X, Y, and Z do NOT exist in project A's
\bin, then I get this exception message when the custom ConfigurationSe ction
handler classes are attempted to be instantiated:
"An error occurred creating the configuration section handler for
NameOfCustomCon figurationSecti onHandler: Could not load file or assembly
'MyCompany.Asse mblyX' or one of its dependencies. The system cannot find the
file specified."

Test 2:
I then place a copy of the assembly containing X, Y, or Z into \bin\Debug.
Note that at this point TWO copies of, assembly X (for example), are in
play - one in C:\SomeFolder, and another in project A's \bin\Debug. Here's
the ensuing exception message:
"Unable to cast object of type 'MyCompany.MyNa mespace.XSettin gs' to type
'MyCompany.MyNa mespace.XSettin gs'."

"XSettings" is the name of my custom ConfigurationSe ction class (real names
changed to protect the innocent).
Notice that this message is telling us that it cannot cast to and from the
EXACT SAME type. This suggests to me that the CLR believes these are
different types [even though the qualified names are identical] BECAUSE they
are loaded from different assemblies - the first being the copy of the
assembly loaded via reflection from C:\SomeFolder and the other assembly
loaded by the .NET Configuration system from project A's \bin\Debug folder.

Attempted Resolution:
In trying to resolve this I started with a look at how the custom
configuration section handler is/can be defined in App.config:
<configSections >
<section name="MySection "
type="MyCompany .MyNamespace.Cl assName, MyCompany.Assem blyX" />
..
What's going on here is the type attribute lets us specify the qualified
class name, a comma, and finally the name of the assembly in which the class
can be found (less the .dll extension of course).

In reading MSDN and points beyond, it appears that we cannot specify a path
to the assembly file here - only the assembly name. The CLR apparently then
attempts to locate the assembly in or under \bin

I then attempted to introduce the <probingeleme nt into App.config to tell
the CLR where to look if it could not find the assemblies in or under \bin:
<runtime>
<assemblyBindin g xmlns="urn:sche mas-microsoft-com:asm.v1">
<probing privatePath="bi n;c:\SomeFolder "/>
</assemblyBinding >
</runtime>

NO dice with that per my testing, plus the docs say that <probingcan ONLY
be used to specify folders under \bin

So I'm fresh out of ideas on how to resolve this. I would appreciate
suggestions for how to make this work. Is there any way to tell the CLR to
load custom configuration section handlers from assemblies that exist
somewhere other than in or under \bin ??? That would be great. If not, I'd
appreciate suggestions for making this work that don't entail me introducing
a bunch of dependencies or breaking out the custom configuration section
handlers into their own\separate assemblies; or otherwise breaking my slick
plug-in architecture. It's taken a bunch of work to get X, Y, and Z to
participate in the application with A knowing absolutely nothing and B
knowing practically nothing about them (and vice versa); I'd like to keep it
like that if possible.

FWIW: This whole thing has been developed from scratch using Visual Studio
2008 Beta 2 (.NET 3.5). and no problems with Beta 2 - totally stable for me
with full-time development since a day or two after it was released.

Thanks!
Aug 22 '07 #1
2 5113
Can you pls ask the question more briefly?
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Smithers" wrote:
I have a Windows Forms application that implements a plug-in architecture
whereby required assemblies are identified and loaded dynamically.

Here are the relevant classes:

A = application = Windows Forms class

B = a singleton hosted within A. B is responsible for dynamically loading
classes X, Y, and Z.

X, Y, and Z = "worker bee" classes that do all of the grunt work of this
application. Each of these classes exists in its own assembly. B loads their
containing assemblies dynamically via reflection:
System.Reflecti on.Assembly.Loa dFile(pathToAss embly).

Being that X, Y, and Z are contained within their respective class
libraries, they cannot have their own .config files. I decided it was okay,
for this particular application, for the App.config file (of A, the
application class) to have custom configuration sections for each of the X,
Y, and Z classes. So X, Y, and Z, if/when loaded, need to read their
respective custom configuration sections from App.config.

Now, to get into the problem area:
I am dynamically loading the assemblies containing X, Y, and Z from
C:\SomeFolder --- and NOT from \bin or a subfolder under \bin

The loading of the assemblies happens just fine, as I am able to specify the
full path to the assemblies via Assembly.LoadFi le(pathToAssemb ly).

So far so good.

Here's where the problem happens:

While X, Y, and Z can read App.config - no problem - the custom
ConfigurationSe ction handler classes, which are also compiled into the
assemblies containing classes X, Y, and Z are INCORRECTLY assumed by the CLR
to exist in assemblies located in or under project A's \bin. I have verified
this through my testing:

Test 1:
If I ensure that the assemblies for X, Y, and Z do NOT exist in project A's
\bin, then I get this exception message when the custom ConfigurationSe ction
handler classes are attempted to be instantiated:
"An error occurred creating the configuration section handler for
NameOfCustomCon figurationSecti onHandler: Could not load file or assembly
'MyCompany.Asse mblyX' or one of its dependencies. The system cannot find the
file specified."

Test 2:
I then place a copy of the assembly containing X, Y, or Z into \bin\Debug.
Note that at this point TWO copies of, assembly X (for example), are in
play - one in C:\SomeFolder, and another in project A's \bin\Debug. Here's
the ensuing exception message:
"Unable to cast object of type 'MyCompany.MyNa mespace.XSettin gs' to type
'MyCompany.MyNa mespace.XSettin gs'."

"XSettings" is the name of my custom ConfigurationSe ction class (real names
changed to protect the innocent).
Notice that this message is telling us that it cannot cast to and from the
EXACT SAME type. This suggests to me that the CLR believes these are
different types [even though the qualified names are identical] BECAUSE they
are loaded from different assemblies - the first being the copy of the
assembly loaded via reflection from C:\SomeFolder and the other assembly
loaded by the .NET Configuration system from project A's \bin\Debug folder.

Attempted Resolution:
In trying to resolve this I started with a look at how the custom
configuration section handler is/can be defined in App.config:
<configSections >
<section name="MySection "
type="MyCompany .MyNamespace.Cl assName, MyCompany.Assem blyX" />
..
What's going on here is the type attribute lets us specify the qualified
class name, a comma, and finally the name of the assembly in which the class
can be found (less the .dll extension of course).

In reading MSDN and points beyond, it appears that we cannot specify a path
to the assembly file here - only the assembly name. The CLR apparently then
attempts to locate the assembly in or under \bin

I then attempted to introduce the <probingeleme nt into App.config to tell
the CLR where to look if it could not find the assemblies in or under \bin:
<runtime>
<assemblyBindin g xmlns="urn:sche mas-microsoft-com:asm.v1">
<probing privatePath="bi n;c:\SomeFolder "/>
</assemblyBinding >
</runtime>

NO dice with that per my testing, plus the docs say that <probingcan ONLY
be used to specify folders under \bin

So I'm fresh out of ideas on how to resolve this. I would appreciate
suggestions for how to make this work. Is there any way to tell the CLR to
load custom configuration section handlers from assemblies that exist
somewhere other than in or under \bin ??? That would be great. If not, I'd
appreciate suggestions for making this work that don't entail me introducing
a bunch of dependencies or breaking out the custom configuration section
handlers into their own\separate assemblies; or otherwise breaking my slick
plug-in architecture. It's taken a bunch of work to get X, Y, and Z to
participate in the application with A knowing absolutely nothing and B
knowing practically nothing about them (and vice versa); I'd like to keep it
like that if possible.

FWIW: This whole thing has been developed from scratch using Visual Studio
2008 Beta 2 (.NET 3.5). and no problems with Beta 2 - totally stable for me
with full-time development since a day or two after it was released.

Thanks!
Aug 22 '07 #2
<snip>
Can you pls ask the question more briefly?
Sure.

Is there any way to tell the CLR to load custom configuration section
handlers from assemblies that exist somewhere other than in or under \bin
???

If the answer to the above question is "no" then...

I'd appreciate suggestions for making this work that don't entail me
introducing a bunch of dependencies or breaking out the custom configuration
section handlers into their own\separate assemblies; or otherwise breaking
my slick plug-in architecture (described in the OP).

Thanks

-S
Aug 22 '07 #3

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

Similar topics

3
2995
by: lanky_tx | last post by:
Hi All, We have an automated build and test environment using NAnt and Nunit. Some of our assemblies are being strong named by modifying the AssemblyInfo.cs and having csc compile it. Some of these strong named assemblies are being dynamically loaded into the runtime. We store the metadata information about the strong named assemblies in a config file. Metadata in the config file looks like this:
4
7010
by: Jonathan Roewen | last post by:
Hi I've got loading assemblies dynamically done (wasn't too difficult). Now I want to lookup a static function in the loaded assembly, and if found, return it somehow, and call it from my app. So far, my efforts have failed miserably My function takes custom objects as parameters, along the lines of: string MyFunction(XmlNode node, MyNamespace.MyObject myObject, String str) { ... I've tried using delegates, and also MethodInfo, but...
1
1953
by: Robert Vasquez | last post by:
I would like my application to be able to load modules dynamically and release them once they aren't needed. For example in c++ I would load a dll containing the required function, run it, then release the dll after it's no longer needed. What are my options in c#? From what I have read so far I can load assemblies containing the required code to execute but I can't release it without releasing the main application domain that loaded it. Is...
0
1328
by: Verane | last post by:
Hi all, I am working with C# and Visual studio 2003. What I want to do is the following : I have 3 assemblies, let call them A.exe, B.dll and C.dll. I want to dynamically load B and C when A is loaded. B and C are statically referencing A. Those three projects are in the same solution called mySolution.
8
4315
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
1
8167
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
1
1665
by: Greg | last post by:
In my ASP.NET application I have a button that when pressed, data needs to be saved based on what the user typed in. I have other controls on the same page that should be updated as a result of the save, which are all dynamically created in the code behind and have event handlers registered. In the page life cycle, event handlers are called after the page is loaded. The problem is, the save is done after the controls are loaded, so the...
6
3802
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection" type="ComIT.Applications.Common.ConfigurationSections.MyHandler" allowLocation="true" allowDefinition="Everywhere" /> </configSections>
3
1970
by: Alexander van Doormalen | last post by:
I have a windows service which calls extensions. In 1 of those extensions I want to load a config file (extension.dll.config). In that config file I defined some ConfigurationSection's. For example: <section name="somename" type="sonenamespace.someclassname, someassembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> The loading part is done using ConfigurationManager.OpenMappedExeConfiguration(ExeConfigurationFileMap,...
0
9563
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...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9937
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
9822
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
6642
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
5270
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
3917
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
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.