Could not load file or assembly System.Net.Security Version=4.0.0.0
- Running coreclr rc1-update1
- webapi inside a docker container
- throws exception on
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("redis:6379"); redismachine 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.
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.
Thanks @NickCraver - i'll hurry up and wait. This was for demo / blog purpose only at this point.
@nickcraver the 2 issues referenced are now closed, can we get a new release?
cc:/ @benadams
@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
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()
@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
@markrendle @glennc ideas here guys?
@spboyer what's the output of dnx --version from the docker image?
@jeremymeng running this base image microsoft/aspnet:1.0.0-rc1-update1-coreclr
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
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/"
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
- add a file
os-release.ubtwith content mentioned above - add a line in
Dockerfileabove the dnu restore line
COPY os-release.ubt /usr/lib/os-release
After making above changes. dnu restore failed for most of the nuget packages

@nishankbangera my workaround is specific to Debian. If you also see the exception on ubuntu it might be a different issue.
@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 No you don't need to. In that base image /etc/os-release is a symbolic link to /usr/lib/os-release.
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?
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
good to know, thank you. I'll give a try
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"]