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

Created on 11 Apr 2017  路  7Comments  路  Source: aspnet/KestrelHttpServer

Steps to reproduce using Visual Studio Professional 2017, 15.0.0+26228.9 and .NET Framework 4.6.01586

  1. New Project > Console App (.NET Framework)
  2. Manage NuGet Packages, Add "Microsoft.AspNetCore" (v 1.1.1)
  3. Program.cs code

    ```c#
    using System.IO;
    using Microsoft.AspNetCore.Hosting;

    namespace API
    {
    internal class Program
    {
    private static void Main(string[] args)
    {
    var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .CaptureStartupErrors(true)
    .UseSetting("detailedErrors", "true")
    .Build();

            host.Run();
        }
    }
    

    }
    ```

  4. Start Debugging

System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.Start(Int32 count)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.StartTContext
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at API.Program.Main(String[] args) in C:\Users\ChristophW\Documents\Visual Studio 2017\Projects\GraphQL\APIProgram.cs:line 19

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

_I suppose i'm somehow approaching this the wrong way - i want a console application running on .net framework 4.6.x for interoperability with existing projects. console application should expose a kestrel API server based on asp.net core._

Most helpful comment

I've had this problem as well. I think this is related to the older project system/tooling (packages.config etc.) not supporting native dependencies and runtime IDs.

I'm not sure if this is/should be supported or not, but I've solved it by just copying libuv.dll to output using MSBuild:

<ItemGroup>
  <None Condition="'$(Platform)' == 'x64'" Include="..\packages\Libuv.1.9.1\runtimes\win7-x64\native\libuv.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Visible>False</Visible>
    <Link>libuv.dll</Link>
  </None>
  <None Condition="'$(Platform)' == 'x86'" Include="..\packages\Libuv.1.9.1\runtimes\win7-x86\native\libuv.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Visible>False</Visible>
    <Link>libuv.dll</Link>
  </None>
</ItemGroup>

This will only work for explicit platforms, i.e. x86 and x64, not AnyCPU. Libuv1.9.1 must, of course, match your installed version of Libuv :smile:

All 7 comments

I've had this problem as well. I think this is related to the older project system/tooling (packages.config etc.) not supporting native dependencies and runtime IDs.

I'm not sure if this is/should be supported or not, but I've solved it by just copying libuv.dll to output using MSBuild:

<ItemGroup>
  <None Condition="'$(Platform)' == 'x64'" Include="..\packages\Libuv.1.9.1\runtimes\win7-x64\native\libuv.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Visible>False</Visible>
    <Link>libuv.dll</Link>
  </None>
  <None Condition="'$(Platform)' == 'x86'" Include="..\packages\Libuv.1.9.1\runtimes\win7-x86\native\libuv.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Visible>False</Visible>
    <Link>libuv.dll</Link>
  </None>
</ItemGroup>

This will only work for explicit platforms, i.e. x86 and x64, not AnyCPU. Libuv1.9.1 must, of course, match your installed version of Libuv :smile:

@khellang thanks for the heads-up! That sounds rather confusing. I've read elsewhere that Kestrel doesn't work with packages.config projects - which leaves me baffling (as i'm new to the whole .net ecosystem and found no other way to create a console app project from VS2017).

What is the best way to get a console application using kestrel and asp.net core that is run on the asp.net framework 4.6.x?

That sounds rather confusing. I've read elsewhere that Kestrel doesn't work with packages.config projects

Yeah, that might be the official story, but by pasting the lines above into my project, I'm happily using ASP.NET Core and Kestrel on full .NET Framework 4.5.2, with packages.config :smile:

What is the best way to get a console application using kestrel and asp.net core that is run on the asp.net framework 4.6.x?

If you want an ASP.NET Core application, running as a console app (all ASP.NET Core apps are console apps), on full .NET Framework 4.6.x, you should be able to use the project template under

File > New > Project... > Templates > Visual C# > Web > ASP.NET Core Web Application (.NET Framework)

image

You can of course select the target framework you want in the dropdown above the templates.

Thanks! I've also got it working using @davidfowl 's comment in #1292. New console applications are now created using PackageReference instead of package.json. After adding Kestrel NuGet package as a dependency, i then need to copy something like this

<PropertyGroup>
  <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
  <BaseNuGetRuntimeIdentifier>win7-x86</BaseNuGetRuntimeIdentifier>
</PropertyGroup>

into the .csproj. Not sure why that works or what the difference is to

About your choice of template in VS2017 - would you prefer "Empty" or "Web API" in the next step to develop a Web API as lightweight as possible?

And what's the difference between that approach and the one from the comment that i've used? :-)

About your choice of template in VS2017 - would you prefer "Empty" or "Web API" in the next step to develop a Web API as lightweight as possible?

I'm probably not the right person to ask, as I'm very opinionated about how my APIs are set up, but I would definitely go for "Empty" and fill in what I need. The defaults usually come with a load of stuff I'm not interested in. See http://benfoster.io/blog/bare-metal-apis-with-aspnet-core-mvc for an example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fanadd picture fanadd  路  9Comments

halter73 picture halter73  路  5Comments

M-Curtis picture M-Curtis  路  3Comments

chtbof picture chtbof  路  3Comments

nmilosev picture nmilosev  路  9Comments