locked
Code Metrics error with silverlight in mscorlib

    Question

  • I have tried to use Visual Studio Ultimate Code Metrics and also have downloaded the code metrics tool from Microsoft and run from the command line and get a similar issue.

    Calculating metrics for file 'C:\Projects\Visual Studio 2010\Projects\SilverlightClient\SilverlightClient\Bin\Debug\SilverlightClient.dll'. Could not unify the platforms (mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) for 'C:\Projects\Visual Studio 2010\Projects\SilverlightClient\SilverlightClient\Bin\Debug\SilverlightClient.dll'.

    I have updated the reference copy mscorlib locally and that hasn't helped

    Tuesday, November 22, 2011 1:25 PM

Answers

All replies

  • Did you run the metrics for more than one project? There's a limitation with both Code Analysis and Metrics where it can only calculate them for compatible versions of the CLR. If you pass in multiple projects or assemblies it will essentially try to use the .NET version of the first one, to calculate for the others as well. To work around this, calculate the metrics using multiple runs, one for each target platform/clr version.

    Another issue might be that the machine you're using to calculate the metrics doesn't have the proper version of the silverlight assemblies installed.


    My blog: blog.jessehouwing.nl
    Tuesday, November 22, 2011 4:44 PM
  • I'm sorry if this isn't totally correct I am still new to the whole .Net development and am getting to grips with how things work.

    I created a clean Silverlight 5 project and that worked without a problem so it isn't to do with that. The solution I have is made up of 3 projects, one that is WPF and the code metrics runs fine against that. Then I have a test application and then the Silverlight 5 app.

    The project I have is made up of multiple third party libraries as well as my own code. the 3rd party libraries are, for the most part, written for Silverlight 4 (or earlier) as obviously Silverlight 5 isn't out yet but the code all works okay.

    I ran my DLL through ILSpy and i appears that there are 2 versions of mscorlib in there which tends to indicate that this is the issue, just not sure how you stop that happening

    Thanks for any help, it is appreciated

     


    • Edited by IcewolfUK Wednesday, November 23, 2011 11:25 AM
    Wednesday, November 23, 2011 11:09 AM
  • Are you using the command line to calculate the metrics? Or are you calling it from inside Visual Studio? I guess that if you invoke metrics from the command line (requires separate download) and supply the assemblies you want to check in the correct order (latest version first), you'd probably get away with the different versions.

     


    My blog: blog.jessehouwing.nl
    Wednesday, November 23, 2011 9:09 PM
  • Have you tried using the /platform command line switch to specify the target framework location?
    Thursday, November 24, 2011 1:02 PM
  • I am using the command line. I am not sure how I go about supplying the references to it but what I have found is that I am able to compile the application as Silverlight 4. When I do this the metrics (and FxCop) are both able to be run so all i can assume is something doesn't like Silverlight 5. But given it hasn't been released yet I suppose having issues isn't unexpected
    Friday, November 25, 2011 10:27 AM
  • I believe it has something to do with ria services being used. Probably with the generated code.
    It is easy to reproduce: just create a new default Silverlight 5.0 Business Application (using the standard Visual Studio template) and try the metrics.exe on the silverlight dll (see below for the command line). Now you will get the error:
    "Could not unify the platforms (mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)"


    However if you create a new default Silverlight 5.0 Application (so not a business application; also using the standard Visual Studio template), then everything will work fine (see command line below).


    metrics on project with BusinessApplication Template
    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\metrics.exe" /plat:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0" /f:"D:\Source\TestProjects\BusinessApplication3\BusinessApplication3\Bin\Debug\BusinessApplication3.dll" /out:"D:\Source\TestProjects\BusinessApplication3\BusinessApplication3\Bin\Debug\CodeMetricsSilverlight.xml" /ignoregeneratedcode


    metrics on project with SilverlightApplication Template
    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\metrics.exe" /plat:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0" /f:"D:\Source\TestProjects\SilverlightApplication26\SilverlightApplication26\Bin\Debug\SilverlightApplication26.dll" /out:"D:\Source\TestProjects\SilverlightApplication26\SilverlightApplication26\Bin\Debug\CodeMetricsSilverlight.xml"


    So, I think I was able to track down the cause, unfortunately I did not yet find a solution.
    Wednesday, March 14, 2012 3:46 PM