1

Ok, think along the lines of a plugin.

I have my own dll and it has it's own functionality. If a third-party dll is present, I'm extending a class inside from that dll.

Everything works great except if the third party DLL is missing. This is the crux of the problem.

I get this exception when the dll is not present:

"Could not load file or assembly 'SOME_THIRD_PARTY_ASSEMBLY, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."

The idea is to allow additional functionality if the third party dll is present, don't allow the functionality if not present.

I know I can use Reflection to test whether a type exists, but in order to get to that part of the code, I have to make it past the above exception.

It's not that I JUST need to know if a class is available, I am also extending the class.

So in order for MY dll to compile, I need to add a reference to the third party dll in Visual Studio.

Can I catch this exception somewhere? Should I go about this differently?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Kevin Giszewski
  • 135
  • 1
  • 8

2 Answers2

2

You could separate the code that was extending the third party DLL into another DLL. Then, in your "extension manager" dll, use a config file to match your extending assemblies with the 3rd party ones.

So, the config file could have an item with two entries like "someClass;inSome3rdPartDll" and then "yourClass;inYourDll".

Go through the config file to see if the listed 3rd party assemblies are present and, if they are, then load you associated assemblies in the app domain.

Now, if you want to extend future 3rd party assemblies, you need only add your dll and add a line to the config file.

Here's a link for help loading assemblies into app domains.

Community
  • 1
  • 1
Justin Self
  • 6,137
  • 3
  • 33
  • 48
0

You could also look into MEF and leverage composition to accomplish this.

https://mef.codeplex.com

code4life
  • 15,655
  • 7
  • 50
  • 82