3

I have an app based on the preview template of ASP.NET 5 RC1 final. I publish the app by running

dnu publish --no-source --runtime active --configuration Release

The resulting package contains the runtime "dnx-clr-win-x64.1.0.0-rc1-final".

When I copy the package to another Windows machine and try to run the web command in the output\approot directory, I receive the following error:

Error: Unable to load application or execute command 'Microsoft.AspNet.Server.WebListener'. Available commands: web, webListener.
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
   at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadFile(String assemblyPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
   at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)

I have tried both Kestrel and WebListener, same error message. The package works on my machine.

Is there anything else that needs to be done to make the app run on another machine?

Martin Klinke
  • 7,294
  • 5
  • 42
  • 64
  • What did you copy to the other machine? The entire `output/bin` folder or just some subfolders in it? – Victor Hurdugaci Nov 19 '15 at 15:44
  • I copied the entire output folder (containing the subfolders approot, logs and wwwroot), no bin subfolder however. – Martin Klinke Nov 19 '15 at 15:48
  • 1
    Check this: http://stackoverflow.com/a/15238782/1184056 – Kiran Nov 19 '15 at 17:05
  • @KiranChalla Thanks, this seems to have solved the problem! Would you care to create an actual answer that I can accept? – Martin Klinke Nov 20 '15 at 09:04
  • Could be the machine you copied to has an earlier version of .net than the machine you are using. There should also be an option to select publish to .net framework instead of .net core (Target DNX Framework) as the Visual Studio GUI has this option – devfric Nov 20 '15 at 18:39

3 Answers3

2

To selfhost an application, I have:

  • deployed to the file-system (to c-drive of my dev machine)
  • changed the entry Localhost:5000 (default) in Hosting.ini (C:[app-name]\approot\src[app-name]\ to the IP-Address of my machine
  • opened the port 5000 in the windows-firewall of my machine

then, I was able to load the application from another machine over the LAN.
Note you have to start the web.cmd as admin
After doing that, I have done the same on our intranet-server (copied the whole deployed directory to the c:-drive of the intranet-server, changed the IP in hosting.ini to the server-ip and opened the port 5000 on the Windows Firewall on the intranet-server).
Then I have started web.cmd as admin on the intranet-server and the app is reachable in the LAN (Server-IP:5000 or DNS-name:5000).
Note: I have just updated to RC1 and there seems to be various changes to the project-template (therefore, I have re-created my small example-project from scratch).
Especially the Hosting.ini-file (where I have changed the Localhost-entry to the machine-IP) is no loger generated / supported.
I don't have found any description yet, how exactly the IP has to be changed instead (according to MS, new in the hosting.json-file), but find-out, that it's possible to change it in the project.json-file.
I have changed:

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

to

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://172.16.1.7:5000",
    "ef": "EntityFramework.Commands"
  },

Now, it works again.
But attention!
I'm sure that should be done on another way (according to MS in the hosting.json-file) but - as I wrote - I don't have found any description to the entry in hosting.json-file but found a hint on the Internet to an older version how to do it in the project.json-file.

So only take this as temporary workaround, until we know, how to do it correct!
And do that only in the deployed directory (not in the VS-project, as else, the local dev-is won't run anymore!

FredyWenger
  • 2,236
  • 2
  • 32
  • 36
  • It is possible to pass the --server.urls parameter to the web.cmd. Your approach has worked for me as well. The problem occurs with a package built in Jenkins via the dnu publish command. I will check out the linked SO answer in Kiran's comment to my original question when I have time. – Martin Klinke Nov 19 '15 at 20:27
  • Hey, great post! Have you found the solution in the hosting.json file? – Stoimen Iliev Feb 05 '16 at 09:32
  • No. I hope that this will be addressed in the final version (else I wrote a message to MS). I can live with that workaround for now. The Selfhosting really works like a charm and very fast (b.t.w.). – FredyWenger Feb 05 '16 at 20:32
2

The problem could be solved by extracting the ZIP file with 7-zip instead of the Windows Explorer, see also: .net local assembly load failed with CAS policy

Thanks to @Kiran Challa for the link.

Community
  • 1
  • 1
Martin Klinke
  • 7,294
  • 5
  • 42
  • 64
0

An alternative to using 7-zip as suggested by @martin klinke you can use the streams -s -d *.* command from sysinternals / technet.

This will unblock files marked as being 'unsafe' (see the link provided by Martin).

This will unblock files recursively (run it in the root of what was your zip).

Community
  • 1
  • 1
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689