Kestrelhttpserver: The trouble with libuv

Created on 8 Apr 2016  路  19Comments  路  Source: aspnet/KestrelHttpServer

As others have experienced, I'm having trouble with a build regarding libuv not being found - specifically in a net452 project. I know the new standard is netstandard and netcore, but until a critical bug is fixed in those I have no choice but to stay with net45#. I am trying to build the application alongside netstandard at the same time, so that when the critical bug is fixed I can fully transition... but until then....

Using this project.json ...

{
    "version": "1.0.0-rc2-10049",
    "description": "",
    "authors": [
        "Ciel"
    ],
    "tags": [
        ""
    ],
    "projectUrl": "",
    "licenseUrl": "",
    "dependencies": {
        "Microsoft.AspNetCore.Identity": "1.0.0-*",
        "Microsoft.AspNetCore.Mvc": "1.0.0-*",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*",
        "Microsoft.AspNetCore.Routing": "1.0.0-*",
        "Microsoft.AspNetCore.Hosting": "1.0.0-*",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
        "Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
        "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-*",
        "Microsoft.AspNetCore.Authentication.Google": "1.0.0-*",
        "Microsoft.Extensions.Logging": "1.0.0-*",
        "Microsoft.Extensions.Logging.Console": "1.0.0-*",
        "Microsoft.Extensions.Logging.Debug": "1.0.0-*",

        "Microsoft.NETCore.Platforms": {
            "version": "1.0.1-*",
            "type": "platform"
        }
    },
    "frameworks": {
        "net452": {
            "imports": [
                "dnxcore50",
                "netcore1.0",
                "netstandard1.5",
                "netcoreapp1.0",
                "netstandardapp1.5",
                "dotnet5.6",
                "portable-net451+win8",
                "net451",
                "net452"
            ],
            "dependencies": {},
            "frameworkAssemblies": {}
        },
        "netstandardapp1.5": {
            "imports": [
                "dnxcore50",
                "netcore1.0",
                "dotnet5.6",
                "portable-net451+win8"
            ],
            "dependencies": {}
        }
    },
    "runtimes": {
        "Win10-x64": {}
    },
    "compilationOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": false,
        "warningsAsErrors": true
    }
}

I get an error when I run dotnet run -f net452 (documented in the section below for 'actual behavior')

Out of curiosity, I found a libuv.dll file from another project and copied it over to my /debug/net452 folder and it actually worked.

Is there a cleaner workaround for this? It's pretty crippling at the moment.

Steps to reproduce

  • create a new folder, within it run a command line command dotnet new
  • delete Program.cs from the output.
  • add a nuget.config file with the contents shown below;
  • add a Startup.cs file with the contents shown below;
  • modify project.json with the contents shown below;
  • run dotnet restore
  • run dotnet run

    nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="aspnet-core" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Startup.cs

using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace MvcSandbox {
    public class Startup {
        public void ConfigureServices(IServiceCollection services) {
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) {
            app.UseMvc
                (routes => {
                    routes.MapRoute
                        (
                            name: "default",
                            template: "{controller=Home}/{action=Index}/{id?}");
                });
        }

        public static void Main(string[] args) {
            var host = new WebHostBuilder()
                .UseDefaultHostingConfiguration(args)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseKestrel()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
}

project.json

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },
    "dependencies": {
        "Microsoft.NETCore.Platforms": {
            "version": "1.0.1-*",
            "type": "platform"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.0-*",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*",
        "Microsoft.AspNetCore.Routing": "1.0.0-*",
        "Microsoft.AspNetCore.Hosting": "1.0.0-*"
    },
    "frameworks": {
        "net452": {}
    }
}

Actual behavior

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: Unable to load DLL 'libuv': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.AspNetCore.Server.Kestrel.Networking.Libuv.NativeMethods.uv_loop_size()
   at Microsoft.AspNetCore.Server.Kestrel.Networking.UvLoopHandle.Init(Libuv uv)
   at Microsoft.AspNetCore.Server.Kestrel.KestrelThread.ThreadStart(Object parameter)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.KestrelEngine.Start(Int32 count)
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)

Expected behavior

Hosting environment: Production
Content root path: c:\Users\Ciel\Documents\Visual Studio 2015\Projects\MvcSandbox
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Version information

(The result of dotnet --info)

.NET Command Line Tools (1.0.0-rc2-002302)

Product Information:
 Version:     1.0.0-rc2-002302
 Commit Sha:  0954049575

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.10586
 OS Platform: Windows
 RID:         win10-x64

Most helpful comment

OK, I surrender. The versioning complexity is too much for me.

All 19 comments

@ciel could you try win7-x64 as the runtime?

@ciel Side note: Remove all imports and add them only when packages fail to restore. Your project.json is badly broken and importing a large set of TFMs like that will only cause subtle problems.

I see. I was not aware that it actually brought in the entire FTM. I thought it was merely a compatibility flag. In that case, may I know the difference between net451 and this portable-net451+win8 I keep seeing in samples?

I showed this issue to @pakrym who is working on some desktop clr related issues. He mentioned you need to make Microsoft.NETCore.Platforms a netcoreapp1.0 specific dependency in addition to removing the extra imports.

As of this exact moment, all of your assertions appear to be correct. However I am not presently able to test this in the exact environment in which it originated. Please give me some time to get to that point again and try to reproduce it thoroughly.

On my local machine, it appeared to work fine - but again when put on IIS, failures commence. This time I have produced a repository for you to try out.

https://github.com/ciel/aspnetcore-issue-samples

Doubtful there's a kestrel issue here. The imports in this file are just wrong, https://github.com/ciel/aspnetcore-issue-samples/blob/libuv/project.json#L22-L24 (don't ever add them unless you know you need them).

What are the instructions to reproduce the problem? Publish then run on IIS? When you run the published output does it work?

I started with the configuration from the start of this thread, and tested it to make sure it failed - and have been working backwards since then and trimming out everything possible and testing it to try and get the build with the least number of imports/dependencies that still reproduces the problem, so the imports were the same in that push. The aspnet-mvc libraries won't work without at minimum an import to portable-net451+win8 though - at least I've been unable to get a restore to succeed without that.

I've run into this problem as well. Any progress on it since April?

Works fine last I checked.

You can't use Kestrel with packages.config unless you manually copy libuv to the output folder. The kestrel package relies on the toolchain understanding the new package format. If you use project.json with csproj or just project.json + xproj it'll work fine.

Sounds like I've got a lot to catch up on, that's mostly Greek to me. I'll try binging those terms, but it sounds like something the NuGet package should address.

I tried manually copying libuv.dll, at first from packages\Libuv.1.9.0\runtimes\win7-x64\native\, but that failed, but when I used the x86 version, success! Thank you..

Nice

Thanks @davidfowl, I found instructions on converting to project.json.. Unfortuately, when I try to re-install the Kestrel package after createing package.json, it tells me:

Microsoft.AspNetCore.Server.Kestrel 1.0.1 is not compatible with .NETFramework,Version=v4.5.
Some packages are not compatible with .NETFramework,Version=v4.5.
Microsoft.AspNetCore.Server.Kestrel 1.0.1 is not compatible with .NETFramework,Version=v4.5 (win).
Some packages are not compatible with .NETFramework,Version=v4.5 (win).

I gather these messages mean that means I can't use Kestrel with a .Netv45 app, though someone commented on stackexchange that it was possible. Any suggestions?

@BurtHarris needs to be 4.5.1+ (e.g. net451) 4.5 isn't supported

OK, I surrender. The versioning complexity is too much for me.

In your project.json change

        "frameworks": {
            "net45": { }
        },

to

        "frameworks": {
            "net451": { }
        },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

neyromant picture neyromant  路  4Comments

halter73 picture halter73  路  5Comments

ayende picture ayende  路  6Comments

M-Curtis picture M-Curtis  路  3Comments

chtbof picture chtbof  路  3Comments