Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there any way to set up Optional Reference Libraries for Executable in .Net?

I'm Developing a EXE application which is later connected to various Plugins (DLL) files,
Now my question Is it possible to create Executable which run with or without DLL.

Program should check for DLL in some folders, and Use it if available.

Example cases:
Case 1: Chrome, Firefox, Visual Studio - Some popular application which is capable of Moding Executable based on additional plugins. Similar system i need to create...
Case 2: Consider developing application that use Excel library to export or import data, But Application should run even when Excel not installed...

Thanks,
Ashok. RD.
Posted
Comments
[no name] 23-Jul-14 10:49am    
Not sure exactly what the issue is. Sounds like you should look into using MEF or similar.
Sergey Alexandrovich Kryukov 23-Jul-14 21:04pm    
I credited this idea in my answer.

Unfortunately, OP accepted a very counter-productive solution referencing a really bad article.
I provide the advise which really works, please see my answer. In fact, my approach is simpler than MEF, so I prefer using it, at least in most cases which are simple enough.

—SA
ZurdoDev 23-Jul-14 10:50am    
Reflection is one way to go.
Sergey Alexandrovich Kryukov 23-Jul-14 21:02pm    
You are right. Unfortunately, OP accepted a very counter-productive solution referencing a really bad article.
I provide the advise which really works, please see my answer.
—SA
Sergey Alexandrovich Kryukov 23-Jul-14 20:43pm    
Why?
—SA

See this[^] CP article. It looks like it's exactly what you need.

SA is correct. Please see this[^] DD article instead.

/ravi
 
Share this answer
 
v2
Comments
Ashok19r91d 23-Jul-14 11:05am    
+5 Something looks like my need...
Ravi Bhavnani 23-Jul-14 11:09am    
If you find it useful, please accept and rate the solution. This will make it easier for others to find it. Thanks.

/ravi
Ashok19r91d 23-Jul-14 11:18am    
already marked...
Sergey Alexandrovich Kryukov 23-Jul-14 20:53pm    
Did you try to use this library yourself? The code I can see is full with nonsense.

First of all, the author takes some substring of the DLL file name and loads it with Assembly.Load. This is not how it works. This method takes long assembly name, which is not a file name. For file name, one would need to use Assembly.LoadFrom. The code does not check up if some classes really implement some plug-in interface. There is no a reasonable way of identification of the class taken from the library. It should be the type implementing some interface known by the host. And so on... In other words, this is not a working solution.

You see, to advise some article, you need to be sure that what you advise makes sense. Such answers can easily mislead people and frustrate them a lot.

—SA
Ravi Bhavnani 24-Jul-14 8:16am    
Hi Sergey, no I didn't run the sample project before recommending it as a possible solution. Thanks for the heads up.

/ravi
First of all, do yourself a big favor: don't use the article referenced in Solution 1.

You really need to use reflection and develop a plug-in architecture. Please see my past answers where I explain all the basic principles:
Access a custom object that resides in plug in dll[^],
Gathering types from assemblies by it's string representation[^],
Dynamically Load User Controls[^].

Alternatively, you can use Microsoft plug-in framework, MEF:
http://en.wikipedia.org/wiki/Managed_Extensibility_Framework[^],
http://msdn.microsoft.com/en-us/library/dd460648%28VS.100%29.aspx[^],
http://mef.codeplex.com/[^].

(Credit to Wes Aday who suggested MEF.)

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900