473,756 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
ReflectionTypeL oadException error

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

and if I look at the LoaderException s the message I get is

{"Com.Corp.Corp Image.CorpImage "}
System.SystemEx ception: {"Method get_CorpImageFi elds in type
Com.Corp.CorpIm age.CorpImage from assembly CorpImage,
Version=1.0.174 1.17159, Culture=neutral , PublicKeyToken= null does not
have an implementation. "}
AssemblyName: "CorpImage, Version=1.0.174 1.17159, Culture=neutral ,
PublicKeyToken= null"
ClassName: "CorpImage"
Message: "Method get_CorpImageFi elds in type
Com.Corp.CorpIm age.CorpImage from assembly CorpImage,
Version=1.0.174 1.17159, Culture=neutral , PublicKeyToken= null does not
have an implementation. "
MessageArg: "get_CorpImageF ields"
ResourceId: 6012
TypeName: "Com.Corp.CorpI mage.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[] DiscoverPluginA ssembliesHelper (
String path, PluginCriteria criteria, Type criteriaType)
{
String[] assemblies;
// Get .dll names
path = Path.Combine(Ap pDomain.Current Domain.BaseDire ctory, path);
assemblies = Directory.GetFi les(path, "*.dll");
try
{
if(assemblies.L ength != 0)
{

ArrayList assembliesInclu ded = new ArrayList();
foreach(String s in assemblies)
{
// Load the assembly (it it's not the control library)
if (s.ToLower().In dexOf("controll ibrary") < 0)
{
Assembly assembly = Assembly.LoadFr om(s);
// Find matching type?
Type[] types = assembly.GetTyp es();
foreach(Type t in types)
{
if(IncludeType( t, criteria, criteriaType))
{
assembliesInclu ded.Add(s);
break; // match found, move on
}
}
}
}
// Get array of matching assemblies
assemblies = (String[])assembliesIncl uded.ToArray(
typeof(String)) ;
}
}
catch (ReflectionType LoadException oEx)
{
throw new Exception("Erro r discovering plugin assemblies",oEx );
}
catch (Exception oEx)
{
throw new Exception("Erro r discovering plugin assemblies",oEx );
}
return assemblies;
}

Any insights greatly appreciated

Endymion Keats
Nov 16 '05 #1
9 4491
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.publi c.dotnet.langua ges.csharp/<47************ *************@p osting.google.c om>

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
ReflectionTypeL oadException 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.Creat eDomain() ?

Regards

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

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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
4709
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 open project) into the forms designer. The project must be compiled for making this work. Now after recompile I need to update the user control with the newly compiled version (maybe something has changed). And THAT
15
2431
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, the compilation seems to work properly almost all of the time. More on this later. If I launch one copy of the IDE, then I can usually compile the project at least once. At some point, the build fails reporting "Could not copy temporary files...
5
2058
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 have yet to receive any replies. If someone could please give me further information I would greatly appreciate it. Sincerely, Jon
2
3067
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 formats. I was looking at writing some type of base application that would allow me to add-in either new assemblies or plugins, don't know how or which way, for different scenarios. We may just recieve a text file so an assembly would handle...
1
1086
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, the objects do not get unloaded out of the ASPNET_WP process when I end the application during debugging, and come back to Visual Studio. I have to manually kill the ASPNET_WP process in order to re-build the dlls, as they are locked - something...
4
4216
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 our application framework assembly. It has no life of its own - it's designed to provide components that are glued together by another, main application assembly - let us call it APP. Thus, APP uses APPFX, and APP is registered with ASP.NET as a...
1
2260
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 memory, SQL 2000 in same box, framework 1.0 and 1.1 installed, apps use mainly 1.0) whose aspnet_wp.exe's memory consumption increases slowly but surely, leading to process restart eventually and then again recollecting memory etc etc
4
2486
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 desirable. I have a web service that, based on an input parameter, dynamically loads A, B or C library. I also understand that an separate AppDomain is needed to explicitly unload the Assembly. No other apps will use these assemblies. Do I need...
12
1715
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 know about the unloading problems. Let's say I don't care for the moment. If I have an assemlbly file at "c:\\assembly.dll" - how do I load it at runtime as if it were references in the project at build time? I know
0
9455
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
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
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...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9708
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
8709
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
6534
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
5140
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...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.