Home > Dotnet 4.5 > Fakes issue with System.Web.Http

Fakes issue with System.Web.Http

I was recently working on some code where I wanted to fake the "System.Web.Http" assembly however I ran into some mysterious problem and thought about blogging about it.

I started by right clicking on the System.Web.Http and selected the "Add Fakes Assembly" option as shown below.

add fakes assembly

And no surprises there I could see the fakes metadata file generated but didn’t see the fakes assembly as such.

Generated fakes metadata file

I compiled my project and got this weird compilation error "The extern alias ‘swhod’ was not specified in a /reference option ‘ ‘"

Fakes compilation error

However, the workaround was simple by adding the following fakes generation xml.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="System.Web.Http" Version="5.2.3.0"/>
  <StubGeneration>
    <Clear/>
    <Add Interfaces="true" />
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add Namespace="System.Web.Http.ExceptionHandling"/>
  </ShimGeneration>
</Fakes>

With above XML I am instructing fakes to only look for interfaces to be Stubbed and generate Shims for any thing under the "System.Web.Http.ExceptionHandling" namespace. With this addition of XML instruction surely my project compiled and no errors were shown, however no fake assembly was generated and this was quite frustrating.

Then I found another hack where I tried generating a fake for another assembly and that did the trick for me. Strange but worked and as you see below I was finally able to generate the fakes for "System.Web.Http" assembly.

Generated fakes assembly

And was able to refer the Shims as shown below.

Using the system.web.http fakes
Advertisements
  1. Flee
    September 12, 2015 at 12:07 pm

    I got the same error when clicking on ‘Add Fakes Assembly’. I fixed it by going to each class in the referenced assembly and cleaning up the ‘using’ statements (Organize Usings > Remove and Sort).

  1. August 15, 2015 at 3:29 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: