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.Reflection.Assembly.LoadFile(pathToAssembly ).
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.LoadFile(pathToAssembly).
So far so good.
Here's where the problem happens:
While X, Y, and Z can read App.config - no problem - the custom
ConfigurationSection 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 ConfigurationSection
handler classes are attempted to be instantiated:
"An error occurred creating the configuration section handler for
NameOfCustomConfigurationSectionHandler: Could not load file or assembly
'MyCompany.AssemblyX' 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.MyNamespace.XSettings' to type
'MyCompany.MyNamespace.XSettings'."
"XSettings" is the name of my custom ConfigurationSection 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.ClassName, MyCompany.AssemblyX" />
..
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 <probingelement into App.config to tell
the CLR where to look if it could not find the assemblies in or under \bin:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;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! 2 5035
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.Reflection.Assembly.LoadFile(pathToAssembly ).
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.LoadFile(pathToAssembly).
So far so good.
Here's where the problem happens:
While X, Y, and Z can read App.config - no problem - the custom
ConfigurationSection 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 ConfigurationSection
handler classes are attempted to be instantiated:
"An error occurred creating the configuration section handler for
NameOfCustomConfigurationSectionHandler: Could not load file or assembly
'MyCompany.AssemblyX' 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.MyNamespace.XSettings' to type
'MyCompany.MyNamespace.XSettings'."
"XSettings" is the name of my custom ConfigurationSection 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.ClassName, MyCompany.AssemblyX" />
..
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 <probingelement into App.config to tell
the CLR where to look if it could not find the assemblies in or under \bin:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;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!
<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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |