0

I started by creating a console app and running as a self host OWIN app. Installed Web API and all works fine.

Now I installed the SystemWeb nuget package, change the type of app to "class library", change output folder to "bin\" only.

When I run the application using IIS Express, first time I load the app, I receive an exception:

Could not load file or assembly 'Microsoft.Owin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I realized that the System.Web.Http.Owin is referencing the Microsoft.Owin -V 2.0.2.0.

In the App.config the following exists:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

Despite the above, still getting the same exception. Any idea?

Thanks

Bill
  • 2,026
  • 9
  • 55
  • 99

3 Answers3

2

I had this. Copy the app.config and rename it to web.config. This will enable IIS/IIS Express to use the necessary binding redirects.

James World
  • 29,019
  • 9
  • 86
  • 120
  • Nothing solved the problem! I had to start with an Empty Website in VS 2013, remove all System.Web references, start with Self-host, then move to IIS, it all works! Starting with a Console app with Self Host then move to IIS, fails to work! – Bill May 24 '14 at 07:13
  • Hmm, not sure what the problem was for you then, since the above definitely worked for me. At least your going now! – James World May 24 '14 at 07:34
  • Yeah, I want to start from a console, but for some reasons, didnt work. Thanks in all cases – Bill May 25 '14 at 07:45
  • @Bill, some xmlns attributes may cause problems: http://www.codeproject.com/Articles/667286/Assembly-Redirection-Doesn-sharp-t-work-in-web-c – Janis Veinbergs Feb 04 '16 at 12:52
0

From the References list, set the Owin DLL to be "Copied Always" on compile.

  • Tried an app with that DLL, I didn't need all those lines in Web.config. Just had the OWIN dll in the BIN folder. It just worked. Try it... –  May 11 '14 at 17:28
  • Create a console app, install SelfHost nuget package, then install WebAPI nuget package, then install SystemWeb package, and try to run the app from iis express. – Bill May 12 '14 at 11:11
0

I don't think the binding redirect is doing anything for you since the version you referenced (2.0.2.0) isn't in the binding redirect.

You can use the Assembly Binding Log Viewer (Fuslogvw.exe) tool to debug type load exceptions.

Noel
  • 3,288
  • 1
  • 23
  • 42