Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shims warning messages

I am having small application in which I used SHIMS.

So as you know it gives warning like "Warning 20 Some fakes could not be generated. For complete details, set Diagnostic attribute of the Fakes element in this file to 'true' and rebuild the project."

So as said in the warning I tried to set the Diagnostic flag to true.

So as specified I got all the list of warning.

The number of warnings are 1933 from "mscorlib.fakes" file.

So to solve it I just took a look of all the following links check it out.

http://msdn.microsoft.com/en-us/library/hh708916.aspx#bkmk_type_filtering

vs 2012: Shims compile

Suppressing Microsoft Fakes warnings

http://connect.microsoft.com/VisualStudio/feedback/details/848682/microsoft-fakes-not-creating-properties-in-a-shim-of-a-class-with-auto-generated-properties

and other stuff.

But still I am unable to figure out how to solve all this warnings.

I also want to know is there any way to Suppress this warnings.

So how can I remove all this warnings in right way? And is there any other way to suppress all this warnings?

Whenever I am adding

<ShimGeneration>
    <Clear/>
    // other tags like add and etc..
<ShimGeneration/>

I am getting lots of errors in project like you are missing assembly reference and others.

So what is the way to clear out all this warnings and the way to suppress all this warnings?

like image 699
Nirav Kamani Avatar asked Jul 14 '14 09:07

Nirav Kamani


3 Answers

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="mscorlib" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear />
  </StubGeneration>
  <ShimGeneration>
    <Clear />
    <!-- Add or remove library or class --> 
  </ShimGeneration>
</Fakes>
like image 59
Abhishek Sankhat Avatar answered Oct 23 '22 16:10

Abhishek Sankhat


There are two ways of solving when it produces some extra warnings e.g.

Cannot generate shim for System.Diagnostics.ProcessPriorityClass: type is an enum.

Which you might not like, you can get rid of these warnings by not generating Shims for those types in the fakes file. Something like:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="System" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.Diagnostics.Process"/>
    <Remove FullName="System.Diagnostics.ProcessPriorityClass"/>
    <Remove FullName="System.Diagnostics.ProcessWindowStyle"/>
  </ShimGeneration>
</Fakes>

However going through and removing every single class that has a warning can be time consuming especially for larger BCLs.

The second approach, and better in my opinion, is to use type filtering with '!' and only specify the class you are interested in generating. The examples given on MSDN seem to indicate that type filtering can only be used to restrict the namespace attribute but can also be used with the fullname attribute like this example:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="System" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.Diagnostics.Process!"/>
  </ShimGeneration>
</Fakes>

This example will only Shim the System.Diagnostics.Process class and not match System.Diagnostics.ProcessPriorityClass.

like image 12
Martin Avatar answered Oct 23 '22 16:10

Martin


try the Following code

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="mscorlib" />
      <!-- user code -->
      <StubGeneration>
        <Types>
          <Clear />
          <Add AbstractClasses="true"/>
        </Types>
      </StubGeneration>
      <!-- /user code -->
    </Fakes>
like image 2
Human Avatar answered Oct 23 '22 16:10

Human