简体   繁体   中英

AmbiguousMatchException when starting ASP.NET 5 (MVC 6) Web Application

Been trying to wrap my head around this for a few hours now, and gotten to the point of almost giving up.

I've tried searching (both google and SO) but it seems as if nobody has had this problem (and posted about it).

My problem is the following:
I have a simple ASP.NET 5 MVC 6 application; currently it does absolutely nothing (code-wise).

I had a couple of problem earlier with it, but managed to work through it gritting my teeth.

This problem has decided to stick around for a while.

Starting the application (either with debugging or with the "k web" / "k kestrel" command, i get the following exception:

System.Reflection.AmbiguousMatchException: Ambiguous match found.
   at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetMethod(String name, BindingFlags bindingAttr)
   at System.Reflection.TypeInfo.GetDeclaredMethod(String name)
   at Microsoft.AspNet.Hosting.Startup.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean  required)
   at Microsoft.AspNet.Hosting.Startup.StartupLoader.LoadStartup(String applicationName, String environmentName, IList`1 diagnosticMessages)
   at Microsoft.AspNet.Hosting.Startup.StartupManager.LoadStartup(String applicationName, String environmentName)
   at Microsoft.AspNet.Hosting.HostingEngine.EnsureApplicationStartup(HostingContext context)
   at Microsoft.AspNet.Hosting.HostingEngine.EnsureApplicationDelegate(HostingContext context)
   at Microsoft.AspNet.Hosting.HostingEngine.Start(HostingContext context)
   at Microsoft.AspNet.Hosting.Program.Main(String[] args)

My config.json:

{
    "webroot": "httpdocs",
    "version": "1.0.0-beta3",
    "exclude": [
        "httpdocs"
    ],
    "packExclude": [
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "dependencies": {
        // ASP.NET:
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
        "Microsoft.AspNet.Mvc": "6.0.0-beta3",
        "Microsoft.AspNet.Mvc.Razor": "6.0.0-beta3",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta3",

        // "Microsoft.Framework"
        "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3",
        "Microsoft.Framework.DependencyInjection": "1.0.0-beta3",
        "Microsoft.Framework.Logging": "1.0.0-beta3",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta3",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta3"

        //"System.Net.Http": "4.0.0-beta-22416",
        //"mongocsharpdriver": "1.10.0"
    },
    "commands": {
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
        "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5002"
    },
    "frameworks": {
        "aspnet50": { }
    }
}

My Startup.cs (basically standard from example):

using System;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Logging.Console;
using Microsoft.AspNet.Diagnostics;

namespace MausSite
{
    public class Startup
    {
        public IConfiguration Configuration { get; private set; }

        public Startup(IHostingEnvironment env)
        {
            Configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddConsole();

            // Add the following to the request pipeline only in development environment.
            if (String.Equals(env.EnvironmentName, "development", StringComparison.OrdinalIgnoreCase))
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }

        public void Configure(IApplicationBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        }
    }
}

I have basically commented out all of my code to make sure that it's not that which is causing the exception (considering the stack-trace, this doesn't seem very likely either).

Has anybody encountered this before, or something similar?
All ideas welcome!

EDIT: I'm using "klr-clr-win-x86 1.0.0-beta3" / "klr-clr-win-x64 1.0.0-beta3"
The error is persistent on both.
Updated my project.json as well.

Found the problem. It was hidden at the bottom of the file: the Configure methods.

Remove the second one ( Configure(IApplicationBuilder app) ) and everything should work. We don't support overloads for Configure . The startup class can only have one public Configure method.


Previous answer:

  1. Add at least a framework to the frameworks section in project.json like here . Since you are using mongocsharpdriver , you only need aspnet50 because there is no Mongo driver for CoreCLR.
  2. Remove System.Net.Http . It doesn't look like your code needs it.

If the two things above don't solve the problem, tell us what KLR version are you using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM