locked
_ASP.NET Web API - 4.6. with netstandard2 ref = MissingMethodException RRS feed

  • Question

  • User-1704512657 posted

    Hi,

    we have a legacy project in house that is net 4.6.2 web api--- adding a netstandard2 nuget reference with autorest generated client causes the exception

    MissingMethodException 'Void System.Web.Http.Routing.HttpMethodConstraint..ctor(System.Net.Http.HttpMethod[])'." string <sub></sub><sup></sup>

    the offending code setup)

    autofac container calls initbootstrappers (via Common.Autofac.Boostrap) and we have routing bootstrapper

      internal class HttpRouteBootstrapper : IBootstrap
        {
            private static readonly NLog.ILogger Logger = NLog.LogManager.GetCurrentClassLogger();

            private readonly HttpRouteCollection _routes;

            public HttpRouteBootstrapper(HttpRouteCollection routes)
            {
                _routes = routes;
            }

            public void Init()
            {
                if(Logger.IsTraceEnabled) Logger.Trace("Init");

                _routes
                    .MapHttpRoute(
                        "UpdateResourceStatus",
                        "v1/{controller}/{action}",
                        new { action = "UpdateStatus"},
                        new { httpMethod = new HttpMethodConstraint(new HttpMethod("Put")) });

    ....

    the HttpMethodConstraint is what blows up but I do not see why that should be the case. 

    removing the reference removes the issue.

    Tuesday, December 12, 2017 4:52 PM

All replies

  • User283571144 posted

    Hi OisinHaken,

    we have a legacy project in house that is net 4.6.2 web api--- adding a netstandard2 nuget reference with autorest generated client causes the exception

    MissingMethodException 'Void System.Web.Http.Routing.HttpMethodConstraint..ctor(System.Net.Http.HttpMethod[])'." string <sub></sub><sup></sup>

    the offending code setup)

    According to your description, we couldn't directly find the reason why causing this error.

    Could you please tell me which Nuget Package you have installed?

    Besides, if you could provide a test project(in github or onedrive) for us to repro the issue, it will be more easily for us to repro the issue and find the solution.

    Best Regards,

    Brando

    Wednesday, December 13, 2017 2:37 AM
  • User-1704512657 posted

    Hi Brando ZWZ,

    I have created sample project - pushed it to GitHub - https://github.com/VaclavK/HttpMethodConstraint2.git

    if you try to run it, it will throw the exception as above even though that constructor on HttpMethodConstraint should be available... the package that causes the issue - Beatles.Meta.Core - is a very vanilla netstandard2  package with few interfaces.... The issue seems to be that the package "links" in the netstandard (for net47)  dlls and they somehow cause the missing method  - the mechanism is not yet clear to me though

    Wednesday, December 13, 2017 9:53 AM
  • User283571144 posted

    Hi OisinHaken,

    if you try to run it, it will throw the exception as above even though that constructor on HttpMethodConstraint should be available... the package that causes the issue - Beatles.Meta.Core - is a very vanilla netstandard2  package with few interfaces.... The issue seems to be that the package "links" in the netstandard (for net47)  dlls and they somehow cause the missing method  - the mechanism is not yet clear to me though

    I also download the Beatles.Meta.Core package source code, I found its dependencies is net core 1.1.

    See this image:

    So I think this package could only used in net core application couldn't be used in net47.

    If you want to use this package, I suggest you could consider converting your application using net core.

    Best Regards,

    Brando 

    Thursday, December 14, 2017 6:10 AM
  • User-1704512657 posted

    Hi,

    I don't think that it is correct - netstandard is a meta framework and is intended for exactly these reasons - portability - the full framework as well as net.core implement this standard and therefore libraries that conform to netstandard can be used in both those contexts.

    e.g. https://elanderson.net/2016/10/create-a-net-standard-library-for-use-with-full-net-framework/

    You can create e.g. full 4.7 console app and use the beatles.meta.core package in it w/o any problems.

    As the app is legacy  we are not currently in a position to convert it to asp.net core

    Kind regards.

    Oisin

    Thursday, December 14, 2017 12:06 PM
  • User283571144 posted

    Hi OisinHaken,

    In my opinion, this issue is related with the Beatles.Meta.Core package, I also reproduce the error.

    I suggest you could open an issue on the github to ask the product developer to solve this issue.

    The link as below:

    https://github.com/eShopWorld/meta-core/issues

    Best Regards,

    Brando

    Friday, December 15, 2017 1:57 AM
  • User-1704512657 posted

    Hi Brandon,

    I appreciate your help. I do not think the issue is the package - in fact you can repro this using any other netstandard package. 

    But primarily, going back in the thread, the sample itself works (and you can use artefacts from the referenced package) as long as you do not use the httpmethodconstraint. with that code commented out, the app works as expected. This is what makes me to think this is a genuine asp.net issue but I also realise that ultimately we may have to look into switching to asp.net core

    Friday, December 15, 2017 7:55 AM