Swashbuckle.webapi: Method not found

Created on 11 Aug 2015  路  9Comments  路  Source: domaindrivendev/Swashbuckle.WebApi

Any idea?

Method not found: 'Swashbuckle.Application.SwaggerEnabledConfiguration Swashbuckle.Application.HttpConfigurationExtensions.EnableSwagger(System.Web.Http.HttpConfiguration, System.Action`1)'.

Most helpful comment

Hoping I can help others that might run into this issue. To debug what was happening, I disabled the PreApplicationStartMethod of SwaggerConfig.cs and inserted the following code into a web api handler:

{
    var c = new SwaggerEnabledConfiguration(GlobalConfiguration.Configuration, s => "", new List<string>());
    Console.WriteLine("Success");
}
catch (Exception ex)
{
    Console.WriteLine("Failure");
    Console.WriteLine(ex.Message);
}

This gave me a much more descriptive error message:

Cannot convert from 'System.Web.Http.HttpConfiguration [System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]' to 'System.Web.Http.HttpConfiguration [System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]'

Using that error message, all I needed to do was update my binding redirects in the web.config and I was good to go:

      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>

Hope that can help someone else that finds this!

All 9 comments

do you have a "using Swashbuckle.Application" in your cs?

Yes I have using Swashbuckle.Application in the header of my SwaggerConfig.cs

The project work well if I run it in IIS express, the exception happens when I publish it to the local IIS.

That sounds like an issue with deployment. Have you checked that all necessary DLLs are being copied to your local IIS folder? Is there possibly an older version of the DLL which your local IIS is using that IIS Express is not?

I agree with @MerickOWA, this must be related to some stake DLL lying around in your bin folder.

Feel free to re-open if you have more info to provide

Same issue - has been deployed multiple times and via multiple methods, works from within IIS Express, but not full IIS.

Hoping I can help others that might run into this issue. To debug what was happening, I disabled the PreApplicationStartMethod of SwaggerConfig.cs and inserted the following code into a web api handler:

{
    var c = new SwaggerEnabledConfiguration(GlobalConfiguration.Configuration, s => "", new List<string>());
    Console.WriteLine("Success");
}
catch (Exception ex)
{
    Console.WriteLine("Failure");
    Console.WriteLine(ex.Message);
}

This gave me a much more descriptive error message:

Cannot convert from 'System.Web.Http.HttpConfiguration [System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]' to 'System.Web.Http.HttpConfiguration [System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]'

Using that error message, all I needed to do was update my binding redirects in the web.config and I was good to go:

      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>

Hope that can help someone else that finds this!

Thanks @phhlho adding just reference if System.Web.Http, it worked for me.

My fix for this issue came from this thread:

781

Different problem, but same fix

Still can't get this to work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joseph-ortiz picture joseph-ortiz  路  4Comments

nf17 picture nf17  路  4Comments

niemyjski picture niemyjski  路  3Comments

jaxidian picture jaxidian  路  4Comments

Misiu picture Misiu  路  3Comments