I added ServiceStack to a working asp.net core project on a Cloud9 Ubuntu VM, and am getting the following error:
Hosting environment: Production
Content root path: /home/ubuntu/workspace/cms
Now listening on: https://0.0.0.0:8080
Application started. Press Ctrl+C to shut down.
Unhandled Exception: System.UnauthorizedAccessException: Access to the path '/sys/class/net/lo/operstate' is denied. ---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at System.IO.UnixFileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported) at System.IO.UnixFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent) at System.IO.UnixFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.InternalReadAllText(String path, Encoding encoding)
at System.IO.File.ReadAllText(String path)
at System.Net.NetworkInformation.LinuxNetworkInterface.GetOperationalStatus(String name)
at System.Net.NetworkInformation.LinuxNetworkInterface..ctor(String name)
at System.Net.NetworkInformation.LinuxNetworkInterface.GetOrCreate(Dictionary`2 interfaces, String name)
at System.Net.NetworkInformation.LinuxNetworkInterface.<>c__DisplayClass5_0.<GetLinuxNetworkInterfaces>b__2(String name, LinkLayerAddressInfo* llAddr) at Interop.Sys.EnumerateInterfaceAddresses(IPv4AddressDiscoveredCallback ipv4Found, IPv6AddressDiscoveredCallback ipv6Found, LinkLayerAddressDiscoveredCallback linkLayerFound)
I just created an Ubuntu VM (same OS version) on my local machine, and did not have the same problem, I was able to run the app just fine (which is basically just a few lines for an empty AppHost and adding 1 line to the Startup.cs file), so looks like it’s a Cloud 9 permission thing …
I’m wondering then if there are special permissions that are required to run ServiceStack … I’d really like to be able to run ServiceStack on Cloud9 … Thought I’d ask here first. I see the same stacktrace here, but not sure if it’s related.
hmmm weird the only place this is getting called in ServiceStack is already being handled, so this shouldn’t have caused ServiceStack to stop working. Is ServiceStack failing to start completely, i.e. doesn’t respond to any HTTP Requests?
Do you have any more information on the StackTrace, i.e. where GetAllNetworkInterfaceIpv4Addresses() is being called from.
Error seems to occur on first HTTP request that hits ServiceStack in the pipeline. I don’t get why the Exception isn’t caught internally in the catch statement inside ServiceStack (as you mention). I see that @xplicit might be trying to track this down
It’s a .NET Core serious bug, It cannot handle exception when it raised inside this method. (Also it can’t get NetworkInterfaces info, but this could be skipped if it was handle exception). I tried to find a workaround with enabling/disabling interfaces, changing permissions, etc, but nothing helps. Currently I see only one way to avoid this situation while it won’t fixed in .NET Core: when OS is linux try to read content of the file File.ReadAllText("/sys/devices/virtual/net/lo/operstate"); if it throws exception then do not call GetAllNetworkInterfaces()
Yeah ok looks like it’s a serious issue that needs to address in the CoreFx libraries, we’ll have to wait to see how MS addresses it before hard coding a solution in the code-base. In the meantime I’ve added a flag you can disable to prevent accessing the problematic NetworkInformation APIs:
@mjc Awesome glad to hear it Matt! We’re very interested in your progress with .NET Core, please let us know if you run into any more issues or if you’ve got something public you can show us - we love to see more examples of ServiceStack running on .NET Core