StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

Could not load file or assembly System.Net.Security Version=4.0.0.0

Open spboyer opened this issue 10 years ago • 27 comments

  • Running coreclr rc1-update1
  • webapi inside a docker container
  • throws exception on ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("redis:6379");
  • redis machine can be PING'ed from container
  • running webapi outside of container can successfully read/write by IP 192.168.99.100:32783 (container IP:port)

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

spboyer avatar Jan 29 '16 20:01 spboyer

How are you running the code, DNX? Relevant issues: https://github.com/dotnet/corefx/issues/4533 and https://github.com/aspnet/dnx/issues/3183 TL;DR (those are pretty long): There was a bug on rc1-final of DNX, it's only fixed in later rc2 builds.

We'll definitely be doing an RC2 update here as soon as it's nearing to fix many things missing or potentially broken in RC1, but we'll need the Microsoft bits in place before we can update on the lib side.

NickCraver avatar Jan 31 '16 14:01 NickCraver

Thanks @NickCraver - i'll hurry up and wait. This was for demo / blog purpose only at this point.

spboyer avatar Feb 02 '16 18:02 spboyer

@nickcraver the 2 issues referenced are now closed, can we get a new release?

cc:/ @benadams

spboyer avatar Feb 05 '16 22:02 spboyer

@spboyer new release is up on NuGet: 1.1.572-alpha (we'll being dogfooding this today): https://www.nuget.org/packages/StackExchange.Redis/1.1.572-alpha

NickCraver avatar Feb 08 '16 15:02 NickCraver

just gave it a run

 Microsoft.AspNet.Server.Kestrel[13]
      An unhandled exception was thrown by the application.
      System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

      File name: 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
      File name: 'System.Net.Security'
         at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
         at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
         at StackExchange.Redis.ConfigurationOptions.Clear()
         at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown)
         at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration)
         at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log)
         at webapi.Controllers.HeroesController..ctor()
         at lambda_method(Closure , IServiceProvider , Object[] )
         at Microsoft.AspNet.Mvc.Infrastructure.DefaultTypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
         at Microsoft.AspNet.Mvc.Controllers.DefaultControllerFactory.CreateController(ActionContext actionContext)
         at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAllActionFiltersAsync>d__52.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeExceptionFilterAsync>d__51.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__44.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at Microsoft.AspNet.Mvc.Routing.InnerAttributeRoute.<RouteAsync>d__10.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.<Invoke>d__8.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at Microsoft.AspNet.Hosting.Internal.HostingEngine.<>c__DisplayClass32_0.<<Start>b__0>d.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
         at Microsoft.AspNet.Server.Kestrel.Http.Frame.<RequestProcessingAsync>d__79.MoveNext()

spboyer avatar Feb 08 '16 16:02 spboyer

@NickCraver Here is the use case. When running under DNX on local OSX it is a non issue. The Security exception happens when running the application within a Docker Container. Here is the repo where you can see the code reduces to the /api/values -> https://github.com/spboyer/redis-api

dnu restore
docker build -t redis-api .
docker run -d --name "redis-api" -p 5002:5002 redis-api

browse to http://localhost:5002/api/values

spboyer avatar Feb 08 '16 19:02 spboyer

@markrendle @glennc ideas here guys?

spboyer avatar Feb 09 '16 13:02 spboyer

@spboyer what's the output of dnx --version from the docker image?

jeremymeng avatar Feb 18 '16 02:02 jeremymeng

@jeremymeng running this base image microsoft/aspnet:1.0.0-rc1-update1-coreclr

spboyer avatar Feb 18 '16 03:02 spboyer

Even I have got the error "Could not load file or assembly 'System.Net.Security" when running from docker. also tried with asp.net 5 on ubuntu instead of debian, still got the same error.

dnx version - 1.0.0-rc1-16202 type - coreclr

nishankbangera avatar Feb 18 '16 10:02 nishankbangera

It's possibly a dnx bug. I have seen a similar exception before on Debian, and was able to workaround by modifying /etc/os-release to have ubuntu ID's. Note that the ordering matters.

PRETTY_NAME="Debian GNU/Linux 8 (jessie)" NAME="Debian GNU/Linux" VERSION="8 (jessie)" ID=ubuntu VERSION_ID="14.04" HOME_URL="http://www.debian.org/" SUPPORT_URL="http://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

jeremymeng avatar Feb 19 '16 00:02 jeremymeng

Even the microsoft/aspnet:1.0.0-rc1-update1-coreclr docker image sets the DNX_RUNTIME_ID environment variable, it seems that dnu restore was not able to restore a couple of runtime nuget packages on Debian.

I just tested that the following workaround works

  1. add a file os-release.ubt with content mentioned above
  2. add a line in Dockerfile above the dnu restore line
COPY os-release.ubt /usr/lib/os-release

jeremymeng avatar Feb 19 '16 09:02 jeremymeng

After making above changes. dnu restore failed for most of the nuget packages

untitled

nishankbangera avatar Feb 19 '16 12:02 nishankbangera

@nishankbangera my workaround is specific to Debian. If you also see the exception on ubuntu it might be a different issue.

jeremymeng avatar Feb 19 '16 17:02 jeremymeng

@jeremymeng I had tried it with debian OS. base image used was microsoft/aspnet:1.0.0-rc1-final-coreclr. I had copied file "os-release.ubt" to " /usr/lib/os-release", do I also need to place it in "/etc/os-release" as stated in one of your previous post

nishankbangera avatar Feb 20 '16 03:02 nishankbangera

@nishankbangera No you don't need to. In that base image /etc/os-release is a symbolic link to /usr/lib/os-release.

jeremymeng avatar Feb 20 '16 05:02 jeremymeng

I still have this error and did not understand which is the best workaround....

If I reference: "System.Net.Security": "4.0.0-beta-23516", The result is: System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security

If instead I reference: "System.Net.Security": "4.0.0-rc2-23826", (taken from the aspnetcidev feed) dnu fails restoring the package during Docker deploy with the following error: "Unable to restore packages"

Any hints please?

raffaeler avatar Mar 10 '16 22:03 raffaeler

I ran into this problem using the same docker image https://github.com/aspnet/aspnet-docker/blob/master/1.0.0-rc1-update1-coreclr/Dockerfile

I was able to get it to work adding this to the project.json dependencies

"System.Net.Security": "4.0.0-beta-", "Microsoft.NETCore.Platforms": "1.0.1-beta-"

and using

dnu restore --runtime=ubuntu.14.04-x64

rudygt avatar Mar 17 '16 14:03 rudygt

good to know, thank you. I'll give a try

raffaeler avatar Mar 17 '16 21:03 raffaeler

I aslo need System.Net.Security - how did you pass dnu restore with flags in dockerimage?

This is my dockerfile (but the restore doesn't work):

FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr COPY . /app WORKDIR /app RUN ["dnu", "restore --runtime=ubuntu.14.04-x64"] COPY . /app EXPOSE 5004 ENTRYPOINT ["dnx", "-p", "project.json", "web"]

wisien92 avatar May 23 '16 13:05 wisien92