Wednesday, April 18, 2012

Workaround for CA0055 Error with Silverlight Projects in Visual Studio 2010

This connect bug describes an issue with creating certain types of Silverlight projects in Visual Studio. If you're referencing Silverlight 4 DLLs from a Silverlight 5 project, you may run into this code analysis/FXCop issue yourself if code analysis is part of your process. The core of the problem is a versioning decision in Silverlight 5 which results in compile-time violation due to loading two different versions of mscorlib in the same project. It manifests as the following error:

Error 2 CA0055 : Could not unify the platforms (mscorlib, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, mscorlib, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) for 'MyProject.Silverlight\obj\Debug\MyProject.dll'.
More information on CA0055 may be found on MSDN.

How to Reproduce the Issue … in theory

In theory, all you need to do to reproduce the issue is reference a SL4-targeted DLL from an SL5 application. However, in practice, there are other factors in play. For example, it may matter which mscorlib version gets loaded first. These steps won't repro the problem on my installation, but I'm putting them out here in case they help you visualize the issue (and also because I had already written them up when I realized they don't repro here -- I don't want all these bits to go to waste). Create a Silverlight 4 class library. Make sure you target Silverlight 4. I named mine SL4ClassLibrary. The actual code is unimportant, but I set it to the following:

namespace SL4ClassLibrary
    public class Class1
        public string Foo = "Bar";

Read more: 10Rem
QR: Inline image 1

Posted via email from Jasper-Net