MissingMethodException on services.AddMvc()
I created a new project using the Asp.Net Core Web Application (.NET Core) template in VS 2015. I chose an empty template. Didn't make any change. Ran the project that was created.
But the services.AddMvc() in the ConfigureServices method in the Startup class throws the following exception:
An exception of type 'System.MissingMethodException' occurred in Microsoft.AspNet.Mvc.Razor.dll but was not handled in user code
Additional information: Method not found: 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Instance(!!0)
Here is my project.json
{
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net451": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Change Microsoft.AspNet.Mvc which is RC1 final to Microsoft.AspNetCore.Mvc: 1.0.0-rc2-final. This couldn't have been a new project unless you have a borked install.
Yeah this is quite suspicious. @phenning have you seen anything like this with RC2?
No, I haven't seen that. I just double checked the shipped template code and didn't see anything unexpected.
Three observations:
- We don't add the MVC package by default in the Empty Web template, only in StarterWeb and WebAPI. Looking back, I don't think we ever had this package in Empty Web, so I really don't know where it could be coming from.
- There should not be a Startup.cs with services.AddMvc(), instead Startup.cs should just be writing Hello World on any request in the Empty template.
- This looks like a ASP.NET Core Web Application (.NET Framework), not an ASP.NET Core Web Application (.NET Core), was this a typo in the issue?
@phenning et al, Sorry guys, I mentioned the wrong template name. It is Asp.Net Core Web Application (.NET Framework).
I am stuck now :(
@girish-a Why are you stuck? Are you still referencing a mix or RC1 and RC2 packages? What are you trying to achieve?
Thank you very much for your response. I shall upload a sample later today.
Hi All, Just to make sure, I created all projects in my solution from scratch and re-added the dependencies. The error is gone now.
The issue was that I was trying to add the "Microsoft.AspNet.Mvc": "6.0.0-rc1-final" package to an ASP.NET Core solution instead of the "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final" package.
The solution that I have consists of multiple projects and hence it took a long time to figure out everything. There were other issues which were coming in the way of diagnosing this issue, but it is all sorted out now.
Thanks a lot. I am closing this issue.