3

How can I suppress the warnings generated by MS Fakes in a build ? I already edited the XML file to generate only the elements we need, but it’s not enough.

Error message

Cannot generate shim for RestServiceHelper`2+<>c: type is not supported because of internal limitations.

XML sample

<Fakes xmlns="schemas.microsoft.com/fakes/2011/"; Diagnostic="false"> 
  <Assembly Name="Common.Api"/> 
  <StubGeneration> 
    <Clear /> 
  </StubGeneration> 
  <ShimGeneration> 
    <Clear /> 
    <Add FullName="RestServiceHelper" /> 
  </ShimGeneration> 
</Fakes>

I have already read this thread before asking my question: Suppressing Microsoft Fakes warnings

Thanks

Community
  • 1
  • 1
Tovich
  • 535
  • 1
  • 5
  • 15
  • What warnings are you getting and what's in the XML file? – doobop Jan 22 '16 at 02:54
  • First warning: "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." With debug: "Cannot generate shim for RestServiceHelper`2+<>c: type is not supported because of internal limitations." The XML: – Tovich Jan 22 '16 at 08:42
  • Without having the .dll in question, it looks like there's a generic type or inner type that's causing an issue. You might to state the Add more specifically with a '!' (or put a Remove that's more specific) in the XML file according to the naming rules at this Microsoft page (https://msdn.microsoft.com/en-us/library/hh708916.aspx). FYI, there's some additional configuration parameters here (http://blogs.msdn.com/b/ajayarora/archive/2014/03/28/configuring-fakes.aspx) which may not apply here. – doobop Jan 23 '16 at 03:09
  • @doobop here is the code: public static async Task Test(string param) Apparently, Microsoft Fakes doesn't like async methods, but we must create a shim for this method. The shim: ShimRestServiceHelper.TestString = (stringRandom) => { ... }; – Tovich Jan 26 '16 at 12:12

2 Answers2

2

You can suppress the warning via the following statement:

<Remove TypeName="&lt;&gt;c" />
Peter Buchmann
  • 157
  • 1
  • 11
  • Wow this worked for me... I had internal class in my assembly and without this I was getting build warning. I copied this in xxx.fakes XML file under and it worked... – Ziggler Feb 26 '19 at 21:40
  • While this works, it is a hacky workaround. I posted an answer that solves this issue in a much more streamlined fashion. – julealgon Aug 02 '19 at 17:26
0

The better way to avoid this issue is to use a stricter filter in the XML file. Add a ! character to the end of the filter to use case sensitive precise matching:

  <ShimGeneration> 
    <Clear /> 
    <Add FullName="RestServiceHelper!" /> 
  </ShimGeneration> 

As per the documentation:

enter image description here

julealgon
  • 7,072
  • 3
  • 32
  • 77