[Fixed] No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' asp.net 5 Linux

vNext Linux Configure

It is a common error can be seen in vNext configure in Linux server. Full error is listed below

System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered.
  at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService (IServiceProvider provider, System.Type serviceType) <0x4098f940 + 0x0005b> in <filename unknown>:0 
  at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T] (IServiceProvider provider) <0x4098f8d0 + 0x00027> in <filename unknown>:0 
  at Microsoft.AspNet.Hosting.Program.Main (System.String[] args) <0x4098e580 + 0x000e7> in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x7f252fdab780 + 0x000a1> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f252fc016d0 + 0x00029> in <filename unknown>:0 
  at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly assembly, System.String[] args, IServiceProvider serviceProvider) <0x4098c9f0 + 0x001b6> in <filename unknown>:0 
  at Microsoft.Dnx.ApplicationHost.Program+<>c__DisplayClass3_0.<ExecuteMain>b__0 () <0x4098c940 + 0x00027> in <filename unknown>:0 
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () <0x7f252fc8cb10 + 0x00053> in <filename unknown>:0 
  at System.Threading.Tasks.Task.Execute () <0x7f252fc9e050 + 0x00055> in <filename unknown>:0 

Solution For The Error

This is because of the version conflict of which you are developed and using in Linux server. One of the major problem of Microsoft is version management. They are simply changing supports and commands in each and every version. For example it is very difficult to run a version 1 web application by using the upgraded version 2. So be careful about that. 

So the problem is you have developed the version using may be version 1 and you are using version 2 in Linux server. One way to resolve the problem is installing and using the specific version in Linux server.

To find out the version which you have developed the application, take a look at the project.json file. You could see like below

Runtime error in Asp.Net 5 vNext
project.json
From the above image we could see that the version is 1.0.0-beta5. So check if there exists the same version in DNVM (Dot Net Version Manager) by using below command

dnvm list
then there will list all the version installed, if you found the 1.0.0-beta5 version, if you are already using 1.0.0-beta5 version then you can see a asterisk (*) symbol along with it. If not then use below command
dnvm use 1.0.0-beta5
If the version is not exists there, then just install it using following command
dnvm install 1.0.0-beta5
which will install the specific version and use it default. After that restore the packages, and build then run it. It will work. If you have any problems occurred, just do comment here.
[Fixed] No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' asp.net 5 Linux [Fixed] No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' asp.net 5 Linux Reviewed by Tech Doubts on 8:42 AM Rating: 5

No comments:

Powered by Blogger.