Question

After installing VS2012 Update 1 I'm unable to create fake assembly for Microsoft.Practices.EnterpriseLibrary.Logging.dll reference. However fakes assemblies for Microsoft.Practices.EnterpriseLibrary.Commom.dll, System.dll and others creates normally. The only solution for this problem I found, was to uninstall Update 1 of VS2012 and things got back to normal. The problem occurred both on local machine and on tfs build server.

Here is the error, that VS2012 shows in its error list:

'Microsoft.Practices.EnterpriseLibrary.Logging.Fakes.StubLogWriter' does not implement inherited abstract member 'Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.GetFilter(string)' [c:\users\administrator\documents\visual studio 2012\Projects\DeleteMe\DeleteMe\obj\Debug\Fakes\mpell\f.csproj]    c:\users\administrator\documents\visual studio 2012\Projects\DeleteMe\DeleteMe\f.cs 68219   DeleteMe    26

I suppose it's a bug of VS2012 Update 1, but maybe I'm missing some property to check or something?

Was it helpful?

Solution

In Visual Studio 2012 Update 1, we removed several internal limitations that caused Fakes silently skip generation of stubs and shims. LogWriter happened to be one of the classes that VS2012 RTM silently skipped. Unfortunately, improvements in Update 1 expose some other limitations in Fakes, which in this case is its inability to distinguish between generic and non-generic overloads of the GetFilter method of the LogWriter class.

As a workaround, remove this type from Fakes configuration. Here is a .Fakes file that accomplishes that.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="Microsoft.Practices.EnterpriseLibrary.Logging" Version="5.0.505.0"/>
  <StubGeneration>
    <Remove FullName="Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter!"/>
  </StubGeneration>
</Fakes>

As a general practice, it is better to modify the default .Fakes files and specify only the stub and shim types you need in your project. This significantly improves build time and helps avoid Fakes limitations that don't apply to your testing needs.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="Microsoft.Practices.EnterpriseLibrary.Logging" Version="5.0.505.0"/>
  <StubGeneration>
    <Clear/>
    <Add FullName="Namespace.TypeName!"/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="Namespace.TypeName!"/>
  </ShimGeneration>
</Fakes>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top