views:

26

answers:

1

If someone were to develop a .NET component that relied on non specific versions of a vendor DLL - let's say it worked with My3rdPartyComponent.dll which is a .NET assembly, but it didn't matter which version.

Some instances of classes found in this component would need to be passed into my component. Developers would reference my component dll but not have access to the source code.

Basically, I want to be able to require the user to pass in an instance of 3rdPartyComponent.MyClass to my component functions but I do not care if it's version 1.1, 2.2, 2.23.980, etc of the 3rd party dll.

Is there a way to do this while still typing the parameter I want to be passed in to my component? I don't want to use Object as the reference.

In my component project I could specify SpecificVersion=True on the assembly reference. Will this solve my problem or will there be other 'dll hell' issues to deal with that I am not seeing?

A: 

Essentially, no, you cannot do what you want (at least not to my knowledge). The entire premise of .NET versioning is that different versions of an assembly are different assemblies. So 3rdPartyComponent.MyClass version 1.1 is a completely different class from 3rdPartyComponent.MyClass version 1.1.1 as far as .NET is concerned. For better or for worse, that is how it works.

If you have no control over the third party assembly then the only way you could support this is using Reflection. The dynamic type in .NET 4 should make it fairly easy - but it's still a hack and will fail if the interface changes in the slightest way (which is, of course, the whole point of versioning).

If you had some control over that assembly you could extract some interfaces into a separate assembly that rarely has any breaking changes, so its version almost never changes. You could then reference the interfaces from that assembly instead of concrete classes.

Evgeny