Mvc icon indicating copy to clipboard operation
Mvc copied to clipboard

MissingMethodException on services.AddMvc()

Open girish-a opened this issue 10 years ago • 7 comments

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%" ]
  }
}

girish-a avatar May 29 '16 20:05 girish-a

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.

davidfowl avatar May 29 '16 20:05 davidfowl

Yeah this is quite suspicious. @phenning have you seen anything like this with RC2?

Eilon avatar May 29 '16 21:05 Eilon

No, I haven't seen that. I just double checked the shipped template code and didn't see anything unexpected.

Three observations:

  1. 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.
  2. 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.
  3. 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 avatar May 29 '16 23:05 phenning

@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 avatar May 30 '16 06:05 girish-a

@girish-a Why are you stuck? Are you still referencing a mix or RC1 and RC2 packages? What are you trying to achieve?

davidfowl avatar May 30 '16 07:05 davidfowl

Thank you very much for your response. I shall upload a sample later today.

girish-a avatar May 30 '16 12:05 girish-a

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.

girish-a avatar May 30 '16 17:05 girish-a