net. 4.6.1 reference error for . netStandart 2.0

Asked

Viewed 136 times

0

I’m having a problem referencing a Standart2.0 project to my api . net Framework 461;

occurs the following have the class:

public class MeuReturn : IHttpActionResult
{
        private readonly string _objeto;

        public MeuReturn(string objeto)
        {
            _objeto = objeto;
        }
        public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            HttpResponseMessage response = 
                                        new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent(_objeto)
            };
            return Task.FromResult(response);
        }

}

to make a custom return, it works 100% but when I refer to the other project and run the API the following error occurs:

An error has occurred. Method Executeasync in type Webapplication3.Controllers.Meureturn of Assembly Webapplication3, Version=1.0.0.0, Culture=neutral, Publickeytoken=null has no implementation. System.Typeloadexception in Webapplication3.Controllers.Homecontroller.error() in lambda_method(Closure , Object , Object[] ) in System.Web.Http.Controllers.Reflectedhttpactiondescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters) in System.Web.Http.Controllers.Reflectedhttpactiondescriptor.ActionExecutor.Execute(Object instance, Object[] Arguments) in System.Web.Http.Controllers.Reflectedhttpactiondescriptor.Executeasync(Httpcontrollercontext controllerContext, Idictionary`2 Arguments, Cancellationtoken cancellationToken) --- End of previous site stack tracking where the exception was generated --- in System.Runtime.Compilerservices.TaskAwaiter.Throwfornonsuccess(Task task) in System.Runtime.Compilerservices.TaskAwaiter.Handlenonsuccessanddebuggernotification(Task task) in System.Web.Http.Controllers.Apicontrolleractioninvoker.d__0.Movenext() --- End of stack tracking from the previous location where the exception was generated --- at System.Runtime.Compilerservices.TaskAwaiter.Throwfornonsuccess(Task task) in System.Runtime.Compilerservices.TaskAwaiter.Handlenonsuccessanddebuggernotification(Task task) in System.Web.Http.Controllers.Actionfilterresult.d__2.Movenext() --- End of stack tracking from the previous location where the exception was generated --- at System.Runtime.Compilerservices.TaskAwaiter.Throwfornonsuccess(Task task) in System.Runtime.Compilerservices.TaskAwaiter.Handlenonsuccessanddebuggernotification(Task task) in System.Web.Http.Dispatcher.Httpcontrollerdispatcher.d__1.Movenext()

I rechecked the microsoft website and theoretically are compatible

  • This code is part of which project? Which one is being referenced in which?

  • .net 4.6.1 reference. net standard 2.0 this project is the isolated problem. the real problem occurs a large project however, this case occurs in a project with practically blank with only this class a controller a method. And the other project . net standard Default(with Class1 and all). to isolate the error; if you want I can provide the code;

  • John, honestly I got a little confused. Let’s try by parts. The code you show in the question is a class library .NET Standard 2.0?

  • Come on: the sample code is a project class. net 461 that eh the api, this project reference the . net standard 2.0 which has nothing in this example

  • You understand @LINQ ?

  • @Joãorafaelcolombo Sends the code of your csproj in the section that points to the target framework

  • @Leandroangelo can take a look at Github https://github.com/joaocolombo/WebApplication1

Show 2 more comments

1 answer

1

Edit Classlibrary.csprj, and add the target of your web application. remembering that the tag is plural: Targetframerowks

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.