473,407 Members | 2,359 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,407 software developers and data experts.

Problem with Dynamic loading of Assemblies

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 "Let Users Add Functionality to Your .NET
Applications with Macros and Plug-Ins" article at MSDN for the dynamic
loading of DLLs

http://msdn.microsoft.com/msdnmag/is...s/default.aspx

We have an interface defined and everything was working fine. Users
would implement the interface and we would load the object dynamically
and our client application would properly implement the functionality.

I then went and create a Library class that would contain objects that
the third party developers need for utilization with their application
development. We have a reference to this Library class in our
Interface, and users need to implement properties that our part of the
library class. Upon adding this, and implementing the interface, our
dynamic loading of DLLs no longer functioned. I get a
ReflectionTypeLoadException error

"One or more of the types in the assembly unable to load."
System.SystemException: {"One or more of the types in the assembly
unable to load."}
_classes: {Length=2}
_exceptions: {Length=1}
LoaderExceptions: {Length=1}
Types: {Length=2}

and if I look at the LoaderExceptions the message I get is

{"Com.Corp.CorpImage.CorpImage"}
System.SystemException: {"Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."}
AssemblyName: "CorpImage, Version=1.0.1741.17159, Culture=neutral,
PublicKeyToken=null"
ClassName: "CorpImage"
Message: "Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."
MessageArg: "get_CorpImageFields"
ResourceId: 6012
TypeName: "Com.Corp.CorpImage.CorpImage"
I can get by the loading issue by skipping the loading of the Library
class when querying the types. While it's a work around, I am not
sure if it will enable everything to work down the road. I am also
unsure what I did :) Why does skipping trying to iterate the getTypes
of the Library dll enable things to work?

Again, the code is pretty similar to the one mentioned in the above
MSDN article. The change to the code I made to skip loading is as
follows...

private String[] DiscoverPluginAssembliesHelper(
String path, PluginCriteria criteria, Type criteriaType)
{
String[] assemblies;
// Get .dll names
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , path);
assemblies = Directory.GetFiles(path, "*.dll");
try
{
if(assemblies.Length != 0)
{

ArrayList assembliesIncluded = new ArrayList();
foreach(String s in assemblies)
{
// Load the assembly (it it's not the control library)
if (s.ToLower().IndexOf("controllibrary") < 0)
{
Assembly assembly = Assembly.LoadFrom(s);
// Find matching type?
Type[] types = assembly.GetTypes();
foreach(Type t in types)
{
if(IncludeType(t, criteria, criteriaType))
{
assembliesIncluded.Add(s);
break; // match found, move on
}
}
}
}
// Get array of matching assemblies
assemblies = (String[])assembliesIncluded.ToArray(
typeof(String));
}
}
catch (ReflectionTypeLoadException oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
catch (Exception oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
return assemblies;
}

Any insights greatly appreciated

Endymion Keats
Nov 16 '05 #1
9 4453
Where is the interface assembly? The assembly resolver will only look in your APPBASE (normally the directory the application is running in) and a subdirectory with the same simple name as the assembly (unless the interface assembly has a strong name). So if your interface is in an assembly called iface.dll and your app is running from the C:\Foo directory, then the assembly resolver will only look in the directories

C:\foo
C:\foo\iface

unless you extend the seatch path via the <probing> element in the appliction config file.

I suspect that when enumerating the types it cannot find the interafce dll for one of the types when it loads the type information

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<47*************************@posting.google.com>

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 "Let Users Add Functionality to Your .NET
Applications with Macros and Plug-Ins" article at MSDN for the dynamic
loading of DLLs

http://msdn.microsoft.com/msdnmag/is...s/default.aspx

We have an interface defined and everything was working fine. Users
would implement the interface and we would load the object dynamically
and our client application would properly implement the functionality.

I then went and create a Library class that would contain objects that
the third party developers need for utilization with their application
development. We have a reference to this Library class in our
Interface, and users need to implement properties that our part of the
library class. Upon adding this, and implementing the interface, our
dynamic loading of DLLs no longer functioned. I get a
ReflectionTypeLoadException error
Nov 16 '05 #2
I tried putting the <Probing> tag into my App.config file and that did
not resolve the issue.

I am not very well versed in Assemblies and application domains. I
believe I am testing the assemblies that implement the interface in a
second domain, and then they get added to my executing application
domain. Could this be part of the issue?

Endymion Keats

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
What makes you say you are running the code in a secondary AppDomain? Have you coded is this way by using AppDomain.CreateDomain() ?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eR**************@tk2msftngp13.phx.gbl>

I tried putting the <Probing> tag into my App.config file and that did
not resolve the issue.

I am not very well versed in Assemblies and application domains. I
believe I am testing the assemblies that implement the interface in a
second domain, and then they get added to my executing application
domain. Could this be part of the issue?

Endymion Keats

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #4

Yes, I am.

The MSDN exmaple code cited above, creates a temporary application
domain. The discovery of the DLLs that implement the interface then
uses this temporary application domain to identify DLLs that implement
the interface. My understanding is the reason this is done because once
you load the DLL into the domain, you can't unload without killing the
application domain, so by creating the second domain, you are able to
reduce your memory footprint.

However, I have tried using both the base application domain and a
temporary one and neither seems to work.

Thanks for the help

Endymion Keats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
We need to test whether my theory of the interface assembly not being loaded is correct. Cna you run up the fusion log viewer (fuslogvw.exe) and check the checkbox which states to log failures. Unfortunateely I can never remember the sequence to see the failed logs - I seem to remember its never as stiaghtforward as it should be. Run the app and let it fail, now see if fuslogvw shows any errors. If not, shut down fuslogvew and restart it - any errors now? If not re-reun the app and let it fail - any errors now? if not shut down and restart fuslogvw - any errors now? If we get to here and there are no errors then I think that its not a cas eof the interafce assembly failing to load.

If you do see an error can yoiu post the log entry so we can see what the asembly resolver tried to do

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<uc**************@TK2MSFTNGP11.phx.gbl>
Yes, I am.

The MSDN exmaple code cited above, creates a temporary application
domain. The discovery of the DLLs that implement the interface then
uses this temporary application domain to identify DLLs that implement
the interface. My understanding is the reason this is done because once
you load the DLL into the domain, you can't unload without killing the
application domain, so by creating the second domain, you are able to
reduce your memory footprint.

However, I have tried using both the base application domain and a
temporary one and neither seems to work.

Thanks for the help

Endymion Keats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #6

I have run the fuslogvw.exe a couple of times and have not seen any
errors.

If I comment out the property I have the implements the Control library
DLL in my interface, I am able to run the application fine, so I am
pretty sure the Interface is loading and executing properly. Once I try
and implement the Control library dll, things stop loaidng.

Endymion Keats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
I'm sorry, I don't know what you mean by "implement the control library"

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#Z**************@TK2MSFTNGP11.phx.gbl>
I have run the fuslogvw.exe a couple of times and have not seen any
errors.

If I comment out the property I have the implements the Control library
DLL in my interface, I am able to run the application fine, so I am
pretty sure the Interface is loading and executing properly. Once I try
and implement the Control library dll, things stop loaidng.

Endymion Keats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #8
Sorry, for the confusion.

I have an Interface, iFoo. I then create a DLL that implements the
interface, clsFooDog. If I do this, everything works fine. I am able
to load the class clsFooDog and access it's methods and properties fine.

My problem comes in the next step I take. I develop a class library (I
call this the ControlLibrary) that has methods and properties that I
want the interface class to implement. So in iFoo, I put a reference
and an imports statement for the ControlLibrary class. I then put a
property in the iFoo interface that uses a collection class in the
ControlLibrary as the type.

Once I do this, I am unable to load clsFooDog.

Thanks Again

Endymion Keats

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

I have discovered the issue that was causing this problem.

In the ControlLibrary class, there was a bug in the constructor that was
causing it to error out.

This is what was causing the error message to be created, because the
type had trouble being instantiated.

Thanks for the help
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #10

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

Similar topics

3
by: Mike Krueger | last post by:
Hi I'm currently working on a forms designer for a free .NET IDE (SharpDevelop -> www.icsharpcode.net/OpenSource/SD). problem: I try to put 'custom' components (user controls from the current...
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
5
by: JonS. | last post by:
Hi, I posted this article ( http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.csharp&mid=0ee9781a-78f7-4398-a0ef-eeb195eccaea&sloc=en-us ) last week, and...
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...
1
by: Harry F. Harrison | last post by:
Hi all... During startup of an ASP.NET app, I have code that dynamically goes out and loads assemblies, looking for objects that implement a particular interface. This code works fine, EXCEPT,...
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...
1
by: Teemu Keiski | last post by:
Hi, I have following type of scenario (also explained here http://blogs.aspadvice.com/joteke/archive/2005/01/10/2196.aspx ) We have problematic web server (wink2 Standard, 1.5GB of physical...
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...
12
by: Ron M. Newman | last post by:
Hi, I can load an assembly using the Assembly.Load(....) However, I'd like dynamic loading of assemblies to be identical to putting an assembly reference in your VS2005 project. and yes, I...
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: 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?
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
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...
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...
0
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,...

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.