Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kestrel with IIS - libuv.dll missing on run

We're setting up an existing Web API server to serve site(s) alongside an existing API. I have been loosely following this article.

Here's what my Global.asax.cs looks like:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        AutoMapperConfig.RegisterMappings();

        var host = new WebHostBuilder()
           .UseKestrel()
           .UseWebRoot("wwwroot")
           .UseIISIntegration()
           .UseStartup<Startup>()
           .Build();

        host.Run();
    }
}

and Startup.cs:

public partial class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        app.UseDefaultFiles();
        app.UseStaticFiles();
    }
}

When I run the project, I get the error

Unable to load DLL 'libuv': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

libuv is a dependency of Kestrel. If I manually copy it from the packages folder to the bin folder, it works. That seems to make sense with this GitHub Issue comment. Now that project.json is being moved away from, how can I get it to copy automatically?

Some have posited that it does not know whether to use 32 or 64 bit version of libuv because the Platform is set to Any CPU in the project properties. I have tried setting it to x64 in both the solution and project settings and the problem persists.

How can I make libuv.dll copy directly to the build directory automatically?

I do not consider including the file in the project (instead of in the packages folder) and setting it to copy to the output directory a real solution, only a workaround. I'm hoping to find a solution, not a workaround.

like image 938
Scotty H Avatar asked May 23 '17 19:05

Scotty H


1 Answers

I've had a similar problem before when migrating projects. Visual Studio may misbehave a lot with mismatched projects.

Simple Answer: You need to change your projects to the MSBuild/csproj format.

To start with, if you are trying to use .NET Core in your solution, then right-click your project(s) in Visual Studio, and if you don't see Edit xxxxxx.csproj then you're likely going to have issues like the one you are reporting above.

Basically, the .NET Core project templates uses different tooling when compiling the project.

The solution below is a generic way to solve almost all issues regarding projects that try to target .NET Core, but wish to use libraries from another framework. There isn't a good tool (so far) to bridge this problem, so you're going to have to go manual-mode.


Let's get started.

The solution is quite simple (but it's a bit tedious).

Step 1: Make a new project using the new MSBuild/csproj format

Create a new project, and select ".NET Core".

step1

In almost all cases, you probably want to avoid using the ASP.NET Core Web Application template, but that's for another discussion all together.

Step 2: Target the correct framework

Right-click the project and select Edit xxxxxx.csproj

<PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <!--you will also probably want to note that you need these for a console app -->
    <OutputType>Exe</OutputType>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

Pick a framework you want to target, and make sure that it's supported (here is a table).
I have used net452 in the above code snippet for an example. You can find out more about the naming here.

step2

Step 3. Repeat for all projects.

You're going to have to do this for every project in your solution to keep Visual Studio from behaving unexpectedly.

There really isn't much online about how to get ASP.NET Core to work well with old frameworks. Hopefully this will help you out. I wish I had this advice earlier on myself.

like image 164
Svek Avatar answered Oct 01 '22 08:10

Svek