aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

No service for type 'Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment

Open thitemple opened this issue 10 years ago • 39 comments

Hi, I'm trying a new mvc application that I generated using yeoman

When I run dotnet restore I have the following errors:

log : Restoring packages for C:\Users\vintem\Documents\projects\TestMvc6\project.json... error: Unable to resolve Microsoft.AspNet.Diagnostics (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.IISPlatformHandler (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.Mvc (>= 6.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.Mvc.TagHelpers (>= 6.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.Server.Kestrel (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.StaticFiles (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.AspNet.Tooling.Razor (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.Extensions.Configuration.FileProviderExtensions (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.Extensions.Configuration.Json (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.Extensions.Logging (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.Extensions.Logging.Console (>= 1.0.0-rc1) for DNX,Version=v4.5.1. error: Unable to resolve Microsoft.Extensions.Logging.Debug (>= 1.0.0-rc1) for DNX,Version=v4.5.1. info : Committing restore... log : Restore failed in 296ms.

Errors in C:\Users\vintem\Documents\projects\TestMvc6\project.json Unable to resolve Microsoft.AspNet.Diagnostics (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.IISPlatformHandler (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.Mvc (>= 6.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.Mvc.TagHelpers (>= 6.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.Server.Kestrel (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.StaticFiles (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.AspNet.Tooling.Razor (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.Extensions.Configuration.FileProviderExtensions (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.Extensions.Configuration.Json (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.Extensions.Logging (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.Extensions.Logging.Console (>= 1.0.0-rc1) for DNX,Version=v4.5.1. Unable to resolve Microsoft.Extensions.Logging.Debug (>= 1.0.0-rc1) for DNX,Version=v4.5.1.

NuGet Config files used: C:\Users\vintem\AppData\Roaming\NuGet\NuGet.Config

But when I open the application using Visual Studio Code, it is able to restore the packages.

After the packages are restored using Code, I ran dotnet run and got the following error:

Unhandled Exception: System.InvalidOperationException: No service for type 'Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.AspNet.Hosting.WebHostBuilder.Build() at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args) at TestMvc6.Startup.Main(String[] args) in C:\Users\vintem\Documents\projects\TestMvc6\Startup.cs:line 61

I'm using: .NET Version Manager v1.0.0-rc2-15546 1.0.0-rc2-16595 clr x86 win .NET Command Line Tools (1.0.0-beta-001598)

Any help? Thanks

thitemple avatar Mar 12 '16 03:03 thitemple

  1. What feeds do you have in NuGet.config?
  2. What's in your project.json file?

victorhurdugaci avatar Mar 12 '16 06:03 victorhurdugaci

This is my project.json file:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "tooling": {
    "defaultNamespace": "TestMvc6"
  },

  "dependencies": {
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1",
    "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1",
    "Microsoft.Extensions.Logging": "1.0.0-rc1",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1"
  },

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

  "frameworks": {
    "dnx451": {}
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "node_modules",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install",
      "gulp clean",
      "gulp min"
    ]
  }
}

And this is the Nuget.config that is in my AppData\Roaming\Nuget

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
</configuration>

thitemple avatar Mar 12 '16 14:03 thitemple

@vintem Change your package references to 1.0.0-rc1-final ... except for Microsoft.AspNet.Mvc and Microsoft.AspNet.Mvc.TagHelpers, those are 6.0.0-rc1-final

guardrex avatar Mar 12 '16 14:03 guardrex

@GuardRex they were like this before, and it didn't work either.

thitemple avatar Mar 12 '16 14:03 thitemple

The runtime should also be on-par with an rc1 project, so I suggest ... dnx-clr-win-x86.1.0.0-rc1-update1.

Regarding the use of dotnet cli, use dnu restore for an rc1 project. dotnet restore is an rc2 thing.

guardrex avatar Mar 12 '16 14:03 guardrex

The runtime I'm using is: 1.0.0-rc1-update1 clr x86 win

I ran dnu restore then dnx run and I got the following error:

System.InvalidOperationException: IHostingBuilder.UseServer() is required for Start()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureServer()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start()
   at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args)
   at Microsoft.AspNet.Hosting.WebApplication.Run[TStartup](String[] args)
   at TestMvc6.Startup.Main(String[] args) in C:\Users\vintem\Documents\projects\TestMvc6\Startup.cs:line 61
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

thitemple avatar Mar 12 '16 15:03 thitemple

@vintem Well, progress, right? :smile:

mmm ... .UseServer() is also for rc2. @victorhurdugaci correct me if I'm wrong, I think that came along in rc2 even after we were using .UseServerFactory(...) in rc2.

I'd suggest you start by clearing the package cache (.dnx packages folder and any packages cached in the project). Restore the project again fresh, which will pull them back down from the feeds. ... and speaking of feeds, I always had the Nuget.org feed as you have, but I also had the vNext one in my rc1-final days ...

<add key="AspNetvNext" value="https://www.myget.org/F/aspnetvnext/api/v3/index.json" />

... it might not matter, but it is a difference between some older projects I have here and your project.

[EDIT] Also note that it might be helpful to review the Announcements for rc1-final. That might highlight how the Startup.cs changed from prior betas.

https://github.com/aspnet/Announcements/issues?q=is%3Aopen+is%3Aissue+milestone%3A1.0.0-rc1

guardrex avatar Mar 12 '16 15:03 guardrex

Hold on, if we're talking about using released stable rc1 bits then there's no reason to add a feed. Everything is on nuget.org.

davidfowl avatar Mar 12 '16 16:03 davidfowl

@davidfowl ... fair enough. I was just identifying a delta between his proj and one of my old ones that had both.

guardrex avatar Mar 12 '16 16:03 guardrex

@GuardRex I've cleaned the packages folder, and my bin/obj folders also removed the .lock.json file and it still doesn't work.

I'm trying to find something on the releases about the startup file specifically but could not find anything.

thitemple avatar Mar 12 '16 17:03 thitemple

@vintem It would still be documented in the official docs for "latest," since that's still the latest stable release. You should see good startup info at ... https://docs.asp.net/en/latest/fundamentals/startup.html?highlight=startup#the-startup-class ... and ... https://github.com/aspnet/Home/blob/dev/samples/1.0.0-rc1-final/HelloMvc/Startup.cs

guardrex avatar Mar 12 '16 18:03 guardrex

I don't think it's the Startup. I've just created a Mvc6 App using Visual Studio Community Edition and the application works if I start it using VS.

If I try to start the same application using dnx I got the same error as before.

thitemple avatar Mar 12 '16 21:03 thitemple

Note your UseServer error is cause by calling dnx run when you should call dnx web instead.

Tratcher avatar Mar 14 '16 17:03 Tratcher

@Tratcher when I run dnx web this is the error I have in response

λ dnx web System.MissingMethodException: Method not found: 'Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor Microsoft.Extensions.PlatformAbstractions.PlatformServices.get_AssemblyLoadContextAccessor()'. at Microsoft.AspNet.Hosting.WebHostBuilder.BuildHostingServices() at Microsoft.AspNet.Hosting.WebHostBuilder.Build() at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args) at Microsoft.AspNet.Server.Kestrel.Program.Main(String[] args) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider) at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.b__0() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()

thitemple avatar Mar 15 '16 00:03 thitemple

If it works in VS and fails on the command line then you most likely have a different DNX selected on the command line. VS uses the DNX specified in the global.json, console does not. Try dnvm list to verify what dnx is active (*).

Tratcher avatar Mar 15 '16 02:03 Tratcher

I'm getting this same error on OSX after upgrading to runtime 1.0.0-rc2-20221. The reason for me upgrading is that SqlClient isn't working in rc1 so I wanted to try if I could get it to run on OSX with rc2. Note that everything runs smoothly on Windows.

EDIT

I noticed that in the original post rc2 was referenced as runtime

tidyui avatar Mar 29 '16 08:03 tidyui

Experiencing same problem as vintern: MissingMethodException: Method not found: 'Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor Microsoft.Extensions.PlatformAbstractions.PlatformServices.get_AssemblyLoadContextAccessor() when running dnx web. I already did a dnu restore and a dnx build, which both ran without errors.

Btw: I am trying to run in Linux (Ubuntu 14), using coreclr rc2. I don't have a global.json (only project source).

kwaazaar avatar Apr 05 '16 19:04 kwaazaar

I have the same problem as @vintem above when publishing with dnx-coreclr-win-arm 1.0.0-rc2-20221.

I started fresh with everything just today, so I think the real problem here is that doing "install latest" on everything gives you lots of rc2 builds, but the VS template/examples still have all rc1. It's a huge pain to manually resolve the dependency errors, either by getting an rc1 win-arm or by getting rc2 of everything else.

@tidyui

Note that everything runs smoothly on Windows.

Windows 10 IoT on ARM still displays the issue, but it seems that's because it's using an rc2 package whereas the default in global.json is 1.0.0-rc1-update1 and the environment default when dnvm is installed now is 1.0.0-rc1-update2. I had to dig around a lot to find an rc1 win-arm build.

NoneGiven avatar Apr 06 '16 15:04 NoneGiven

had the same problem. that was because I have a rc2 version as default. i switched back to rc1 and everything works as normal.

dnvm use 1.0.0-rc1-update1 -r coreclr -p

Bartmax avatar Apr 07 '16 14:04 Bartmax

use 1.0.0-rc1-update1

depend:

"Microsoft.Framework.Runtime.Interfaces": "1.0.0-beta4"

redpanda321 avatar Apr 12 '16 04:04 redpanda321