7

One of the nuget dependencies in my project (Swashbuckle) requires a version of the System.Web.Http library (4.0.0.0) that is older than the version required by the rest of the project (5.2.3.0).

Swashbuckle requires that I write a class implementing a certain interface:

public class OperationFilter : Swashbuckle.Swagger.IOperationFilter { public void Apply(Swashbuckle.Swagger.Operation operation, Swashbuckle.Swagger.SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { } } 

The important part above is the apiDescription parameter of Apply.

When building the project normally, the above compiles and runs fine. However, when I reflect over the running assembly using assembly.GetTypes(),

var asm = System.Reflection.Assembly.GetExecutingAssembly(); var types = asm.GetTypes() 

a ReflectionTypeLoadException is thrown, with the following loader exception details:

Method 'Apply' in type 'OperationFilter' from assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. 

this question references the above exception, but none of the solutions posed seem to work. I tried to solve the issue by adding a bindingRedirect to Web.config:

 <dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> </dependentAssembly> 

However, that didn't seem to do anything.

How can I get this type to load properly?

EDIT: I've created a minimal reproduction of the issue. A build task in BuildTask.targets loads the project assembly and then tries to load all the types. The errors are thrown and displayed.

7
  • Do you have a minimal project reproducing your issue? I would like to try it with my version of Swashbuckle: nuget.org/packages/Swagger-Net Commented Oct 25, 2017 at 14:00
  • @HelderSepu I just added a repro, thanks! Commented Oct 29, 2017 at 23:40
  • That project is not a WebApi... Commented Oct 30, 2017 at 0:05
  • I sent you a PullRequest on GitHub: github.com/JustASquid/TestSwaggerAssemblyIssue/pull/1 Commented Oct 30, 2017 at 0:17
  • @HelderSepu So this is a fork of swashbuckle? Why doesn't swashbuckle itself have the lastest versions? Commented Oct 30, 2017 at 3:20

1 Answer 1

1

Following up on my comments...

I just tested the sample project and this issue can be fixed by using Swagger-Net.

That is my fork of Swashbuckle, I've upgraded all dependencies to the latest and using also latest of the Swagger-UI (3.x), it is quite a drastic change from the old one, let me know how you like it.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not sure I want to move to a library that is not as heavily supported/used as Swashbuckle. Is there a reason Swagger-Net isn't a just a PR to swashbuckle?
What do you mean by not heavily supported? I personally do the support, I fix bugs and add features quite often, just look at the release frequency on NuGet

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.