Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Missing dependencies when publishing net46 to Azure #801

Closed
hultqvist opened this issue Jun 17, 2016 · 37 comments
Closed

Missing dependencies when publishing net46 to Azure #801

hultqvist opened this issue Jun 17, 2016 · 37 comments

Comments

@hultqvist
Copy link

Steps to reproduce

Create a new dotnet core WebApplication project in Visual Studio 2015.

Modify project.json to only target net46:

  "frameworks": {
    "net46": { }
  },

Result

Locally the project worked both in IIS Express and stand-alone.

Then I published it to a web app in Azure, the result was

The specified CGI application encountered an error and the server terminated the process

When logging was activated two exceptions was found.

First one about missing assembly System.IO.FileSystem.Watcher, when that was addressed the message below was logged.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, PhysicalFilesWatcher physicalFilesWatcher)
   at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at WebApplication1.Program.Main(String[] args) in C:\Users\peter\DoltWindows\Documents\Visual Studio 2015\Projects\WebApplication1\src\WebApplication1\Program.cs:line 14

Workaround

After adding dependencies to the two missing files in project.json the published project worked in Azure.

  "dependencies": {
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "System.IO.FileSystem.Watcher": "4.0.0-rc2-24027",
    "System.IO.FileSystem": "4.0.1-rc2-24027"
  },

@Tratcher
Copy link
Member

@anurse can you take a look?

@analogrelay
Copy link
Contributor

@Tratcher I'll try and take a quick look but I'm a bit tight on available bandwidth right now :).

@hultqvist Would you be able to grab your full project.lock.json file from before applying the workaround and post it (to a Gist or something)? Basically if you just revert your workaround, restore, verify it's still broken and then send the lock file that would help immensely :)

@hultqvist
Copy link
Author

@charles-smith
Copy link

charles-smith commented Jun 19, 2016

I can confirm the same issue here, and the fix works too. Thanks @hultqvist.

@davidfowl
Copy link
Member

Create a new dotnet core WebApplication project in Visual Studio 2015.

What exactly did you pick? There's 2 options .NET Core and .NET Framework.

@charles-smith
Copy link

I did .NET Core, but ended up targeting net46 since I decided to use SendGrid.

@davidfowl
Copy link
Member

Can you try the repro steps choosing .NET Framework instead of .NET Core? The template is slightly different.

@charles-smith
Copy link

It looks like it doesn't have a project.json file, so it'd really defeat the purpose.

@analogrelay
Copy link
Contributor

@charles-smith The template for an "ASP.NET Core app on .NET Framework" should have a project.json. Note that it is different from the standard "ASP.NET Web Application" template (which is ASP.NET 4.6)

@charles-smith
Copy link

@anurse David's question said to not use .NET Core, did I miss something?

@Tratcher
Copy link
Member

@charles-smith just confusing naming. There's a template for Asp.Net Core on .NET Framework.

@hultqvist
Copy link
Author

I've tried the other project forms today and out of the box all net461 works.

Actually I can now remove the dependencies I added previously and it still works.

"System.IO.FileSystem": "4.0.1-rc2-24027",
"System.IO.FileSystem.Watcher": "4.0.0-rc2-24027"

However now the core version does not work anymore.

The specified CGI application encountered an error and the server terminated the process.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher(String root)
   at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at WebApplicationCoreCore.Program.Main(String[] args)

I have no idea what to add for System

Might this be an Azure issue since I've not updated my tools as far as I know.

@analogrelay
Copy link
Contributor

@charles-smith Yeah, apologies for the confusion. ASP.NET Core works on both .NET Core and .NET Framework. David wanted you to try ASP.NET Core on .NET Framework (see this diagram for some clarification)

@charles-smith
Copy link

No problem. I finally got a chance to check it, and it worked without a hitch.

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

@anurse - I just hit something similar after I published a project targeting net46 created from template to Antares:

I see two errors:

Application startup exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

and

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The project.json looks like this:

{
  "dependencies": {
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net46": { }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "precompile": [ "dotnet bundle" ],
    "prepublish": [ "bower install" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

How do I troubleshoot this?
(The application works locally just fine)

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

@davidebbo - is it possible to turn on Fusion log on Antares? How do I trouble shoot issues like above?

@davidebbo
Copy link

Before trying fusion logs, can you check whether the relevant DLLs were in fact properly deployed? If not, then it's more of a deployment than runtime issue.

Getting fusion log would probably require getting onto the VM.

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

@davidebbo - the application seems to be deployed properly. I tried a few apps and all that target net451/net452/net46 failed this way. Apps targeting netcoreapp1.0 (standalone because 1.0.0 shared runtime is not installed) work just fine.

@davidebbo
Copy link

Not sure. I guess we only tested .net core. Maybe let's wait till RTM is out and take it from there is it still repros?

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

why does this matter if I target desktop clr?

@davidebbo
Copy link

Ah you're right. I've never tried ASP.NET Core with Desktop CLR, so I know very little about it.

Scenario wise, are there reasons to use it instead of .NET Core? I seem to recall @davidfowl telling me to mostly just focus Azure Web App support on .NET Core.

Do you have a ready-to-push repo that demonstrates the issue with Desktop CLR?

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

I can imagine that you may want to target net46 if the application is using APIs not available in .NET Core. As for the application - I just installed the latest (yetserday's) version of the tooling created a web app from the template and deployed it to an existing website I had.

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

I think I figured this out and made it work. I manually deleted all the files I had in wwwroot and redeployed the app and it started successfully. So maybe it feels I had leftovers from previous app(s) that were picked up incorrectly.

This might be an issue with webdeploy because I had the option to remove the files at destination checked:

image

@davidebbo
Copy link

Please share a repo to remove any potential difference in what we try. Make sure that it repros the issue after git pushing it to a fresh site.

@davidebbo
Copy link

Just saw your comment about removing additional files. Does the issue only occur when switching from Core to Desktop? i.e. if you start with clean site and target Core, I assume all is well?

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

I will try it again to see if I can repro this. Targeting .NET Core worked just fine.

@davidebbo
Copy link

Sorry, I meant "if you start with clean site and target Desktop, I assume all is well?"

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

Yes, this seems to work too. @vijayrkn tried it as well and it worked for him so I kind of expected my issue to be environmental.

@davidebbo
Copy link

Ok, so it seems there is no real issue here. Just left over files causing trouble when switching stack.

@moozzyk
Copy link
Contributor

moozzyk commented Jun 23, 2016

Yes. Looks like it. At most, webdeploy did not clean the site properly and I am going to verify this.

@davidfowl
Copy link
Member

Can we close this bug?

@davidebbo
Copy link

Yep.

@JoseFMP
Copy link

JoseFMP commented Jun 13, 2017

Hello,
This issue still happening. My application is not .ASP but plain .NET 4.6. Same issue though. The application runs flawlessly everywhere, Windows, Linux, Mac, but when deployed to Azure that exception pops.

Any fix?

@vijayrkn
Copy link

vijayrkn commented Jun 13, 2017

@jose-cf - Can you please share a repro project?

What kind of a project is it? Is it a webjob/ASP.NET on full framework?

My application is not .ASP but plain .NET 4.6

@JoseFMP
Copy link

JoseFMP commented Jun 16, 2017

@vijayrkn I tried with a toy example, same result. It is not ASP.NET. It is a simple .NET 4.6 assembly.
To reproduce:

  • Create a .NET 4.6 assembly, as simple as you want.
  • Install System.IO.FileSystem 4.3.0 in it.
  • Create a .NET Standard library using System.IO.FileSystem 4.3.0 package.
  • Install the library in your .NET 4.6 assembly.
  • Run locally works fine (Linux, Windows)
  • Run in Azure fails (net46 referencing netstandard1.3: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0')

I added assembly redirect to 4.0.2.0, still tries to find 4.0.1.0.

@dgioulakis
Copy link

dgioulakis commented Jun 20, 2017

I just ran into this exact same issue as @jose-cf, however, I'm not publishing to Azure; simply publishing locally (/publish). Everything works when run from Visual Studio. Published executable is broken and reports: FileNotFoundException: Could not load file or assembly 'System.Runtime'

Console .NET Framework 4.6.2
.NET Standard Library dll (console depends on this) (requires System.IO.FileSystem)


Update:
I removed from the Console app, my nuget reference to NetStandard as I had a hunch that was unnecessary since my shared lib only required System.IO and there were a number of assembly binding redirects added automatically that seemed incorrect.

I then added the nuget reference to System.IO.FileSystem to the console app. Everything then worked fine in VS and the Published artifacts.

Really odd behavior and most likely a bug somewhere; perhaps in the auto-add of binding redirects?

@JoseFMP
Copy link

JoseFMP commented Jun 21, 2017

@Cephei I think .NET Standard < 2.0 is quite abandoned... seems Microsoft only putting effort in 2.0. 2.0 even in preview has much better support for libraries dependencies.
But still... this is a big issue... cannot even use a basic library to access file system?

jaredcnance added a commit to jaredcnance/dotnet-status that referenced this issue Jul 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants