32 Comments

I was converting a self-hosted ASP.NET Web API application from Microsoft ASP.NET Web API Self Host to use OWIN Self Hosting.  Everything went find until I tried to add the route configuration to the OWIN pipeline.  Samples I found indicate all you have to do is call “UseWebApi” but the IAppBuilder.UseWebApi method did not resolve for me: 

image

 

After some searching around I found that you will need to import the Microsoft ASP.NET Web API 2 OWIN Self-Host Nuget package.

image

image

I didn’t realize that there was a separate Nuget package if you wanted to combine OWIN and ASP.NET Web API.  It was a simple solution and honestly now that I think about it, should have been one of the first things I checked.  This post is for the next person that runs into this issue.

Comments

Comment by david

I was that person. Thanks!

david
Comment by Ami

Ditto. Thanks a lot for this little nugget of wisdom.

Ami
Comment by Andy

Sweet man, thanks so much.

Andy
Comment by Hanu

Good

Comment by Hanu

Good

Comment by erwin

And to save the next person a few steps:

1) In VS:
Tools -> NuGet Package Manager -> Package Manager Console
2) Run:
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost

erwin
Comment by ISHITA

THANKS FOR LETTING US KNOW.

ISHITA
Comment by Mark

<script>alert("Good job!")</script>

Comment by Ursin

Thx!

Ursin
Comment by joe

What namespace do you need to import afterwards?

joe
Comment by Tochi

It's in the Owin namespace in System.Web.Http.Owin.dll (which is in the Microsoft.WebApi.Owin package). You'll want need a reference to the assembly.

Tochi
Comment by Tochi

It's in the Owin namespace in System.Web.Http.Owin.dll (which is in the Microsoft.AspNet.WebApi.Owin package). You'll need a reference to the assembly.

Tochi
Comment by Nik

Thank you

Nik
Comment by Josh

I realize this post is about self hosted OWIN, but if you are using the OWIN pipeline and hosting in IIS instead, then the package you need to install is:
Install-Package Microsoft.AspNet.WebApi.Owin.

Josh
Comment by little

thanks alot

little
Comment by little

thanks alot

little
Comment by Jean

Great, thanks man!

Jean
Comment by Sourav Kings

MAGIC !!!

Sourav Kings
Comment by Olamide

Thanks!!!!

Olamide
Comment by Nebula

1

Nebula
Comment by Jahmal

Thanks, I was stumped.

Jahmal
Comment by Dario

Thanks!!

Comment by thanks

Thanks!

thanks
Comment by Dave

Thank you. Saved me some time too

Dave
Comment by Issy

Thanks! Well done!!

Issy
Comment by Daniel

Another next person helped - thank you!

Daniel
Comment by XFormer

Please refer to the following code -
using System.Web.Http;
using DemoWorkerRole;
using Microsoft.Owin;
using Owin;
using System.Web.Http;

[assembly: OwinStartup(typeof (Startup))]
namespace DemoWorkerRole
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();

// Routing
config.Routes.MapHttpRoute(
"Default",
"api/{controller}/{id}",
new {id = RouteParameter.Optional});
//Configure WebAPI
app.UseWebApi(config);
}
}
}

While this works in one of the solution, but in the other solution it fails to fins app.UseWebApi. Though none of the referenced dlls are missing. There is so much confusion around using
System.Web.Http
Owin, Microsoft.Owin, System.Web, System.ASP.net.WebpApi.OwinSelfHost...

XFormer
Comment by XFormer

Just noticed that after installing nuget package - it changes the version of using System.Web.Http from 4.0... to 5.2....
It's working now, but I am still looking for an article to clear the various namespaces with respect to OWIN, Microsoft.Owin, Web API2, SelfHosted etc.

XFormer
Comment by Alex Avrutin

Thanks!

Alex Avrutin
Comment by talha

thanks

talha
Comment by Dan

Bingo. Thanks.

Dan
Comment by PT Esteve

Spot on. Many thanks.

PT Esteve