7

I have an Asp.net 5 web application that works and runs fine in development (from Visual Studio or VS code I can launch no problem). However, after successfully publishing the app, when trying to launch the website with "web.cmd" the following error appears and prevents the website from ever loading:

Application startup exception: System.IO.FileNotFoundException: Could not load file or assembly 'my-ng2-website' or one of its dependencies. The system cannot find the file specified.
File name: 'my-ng2-website' ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
   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.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Microsoft.AspNet.Hosting.Startup.StartupLoader.FindStartupType(String startupAssemblyName, IList`1 diagnosticMessages)
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()

I have searched high and low for solutions. I can't figure out what dependency I am missing. I've tried

deleting the package.lock.json

dnu restore

Here is my dnx config setting for the project: enter image description here

Here is the settings for the publish:

enter image description here

Can anyone read these tea leaves?

Community
  • 1
  • 1
brando
  • 8,215
  • 8
  • 40
  • 59
  • publish setting changed **my-ng2-website** to **my-ng2-website-compiled** – ymz Jan 20 '16 at 01:08
  • yes that is a typo - but the real publish settings are something completely different. i made up "my-ng2-website" for displaying here – brando Jan 20 '16 at 02:33
  • Is the assembly getting published? Or maybe it's getting renamed when published. – jtlowe Jan 20 '16 at 23:19

3 Answers3

1

Good day. We had few encounters with this type of error. It often times points to a missing assembly (the most common one). Checking all necessary references, set to Copy Local -> true, helps most of the time. Since assemblies/references wont be included in the publish if its set to Copy Local -> false.

Hope this helps.

Jeff
  • 760
  • 1
  • 12
  • 26
  • Where do you set Copy Local -> true? In the public profile there is a CopyLocalFilesOutputGroupDependsOn setting. – brando Jan 21 '16 at 02:47
1

Just for the heck of it, I set the "Compile source files into Nuget Package" to false. And now it works.

enter image description here

Why it works, I don't know. But hopefully this will help someone else.

brando
  • 8,215
  • 8
  • 40
  • 59
0

This error has something to do with the global.json file located in the project directory (not the solution one). If you want to publish the project with the compile option on make sure to add it to publishExclude in your project.json

"publishExclude": [
  "**.user",
  "**.vspscc",
  "global.json"
],