C# – Using different versions of DLL in one application

cdllsilverlightversion

I have a Silverlight Class Library that is being used by both Silverlight application and a regular C# WCF Service.

The Silverlight application calls the WCF service to read/write some data. They both use the common library to manipulate the data being passed.

Everything compiles fine, but when we run the application, the webservice throws the following error when the call to the silverlight library is made:

"Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified."

This is because the silverlight class library is referencing v2.0.5 of System.Xml, but the WCF Service is referencing v3.5 of System.Xml.

Is there a way I can reference both versions and not get the error?

Best Answer

Providing you have the source for the common library then the best approach is to have 3 projects, once for SL, one for WCF and one for the shared library source. You then can reference the source files from the shared lib in the SL and WCF projects using visual studio's add as link option. The source files can then be compiled against the correct .Net library versions. The nice thing about this is due to the source being reference copies, when you make changes to the shared lib, both the SL and WCF projects get updated without any duplication.

We've been using this approach in our product and it works very well.

HTH