Nancy icon indicating copy to clipboard operation
Nancy copied to clipboard

Nancy is not ready for dotnet core 2.1, only for 2.0

Open andersonom opened this issue 7 years ago • 3 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have verified that I am running the latest version of Nancy -
  • [X] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [X] I have searched open and closed issues to ensure it has not already been reported

Description

Nancy is not working for dotnet core 2.1, only for 2.0.

Steps to Reproduce

  • Created a project pointing dotnet core 2.1 web empty project

  • Created MyService calling a external API using Flurl.Http package: `public class MyService : IMyService { private readonly IAppConfiguration _appConfig;

     public MyService(IAppConfiguration appConfig)
     {
         _appConfig = appConfig;
     }
    
     public async Task<MyModel> GetMyModel(string param)
     {
    

return await "httpUrl" .AllowAnyHttpStatus() .AppendPathSegment("parameter") .GetJsonAsync<MyModel>(); } }`

  • Create a injection of a my new class MyService inside my custom Bootstrapper: `public class MyDistanceBootstrapper : DefaultNancyBootstrapper { private readonly IAppConfiguration _appConfig; private readonly IMytService _myService;

      public MyBootstrapper()
      {
      }
    
      public MytDistanceBootstrapper(IAppConfiguration appConfig, IMyService myService)
      {
          _appConfig = appConfig;
          _myservice = myService;
      }
    
      protected override void ConfigureApplicationContainer(TinyIoCContainer container)
      {
          base.ConfigureApplicationContainer(container);
    
          container.Register<IAppConfiguration>(_appConfig);
          container.Register<IMyService>(_myService);
      }
    

    }`

  • When backing to the NancyModule route it throw an exception: `public class MyModule : NancyModule { public MyModule(IAppConfiguration appConfig, IMyService myService) { Get("/Home/param", args => Response.AsJson(myService.GetMyModel((string)args.param)));

      }
    

    }`

  • Exception Process is terminating due to StackOverflowException.

System.StackOverflowException HResult=0x800703E9 Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace>

System Configuration

  • Nancy version: 2.0.0-clinteastwood

  • Nancy host

    • [ ] Nancy.Hosting.Aspnet
    • [ ] Nancy.Hosting.Self
    • [X] Nancy.Owin
    • [ ] Other:
  • Environment (Operating system, version and so on): Windows 10

  • .NET Framework version: dotnet core 2.1

  • Additional information: The same project worked when reverted dotnet core 2.1 to 2.0

andersonom avatar Aug 07 '18 12:08 andersonom

+1

wjdavis5 avatar Aug 28 '18 14:08 wjdavis5

I just tested Nancy (pre1911) with Core 2.1 and it works just fine. I changed a few things compared to the code you posted:

  • GetMyModel is async, so it should be called in an async manner, something like:
Get("/Home/{param}", async (args, ct) =>
{
    var result = await myService.GetMyModel((string) args.param, ct);
    return Response.AsJson(result);
});

In your code, the Task object is serialized to JSON, which is not what we want.

Also, I just did this to have the service managed entirely by TinyIoC:

container.Register<IMyService, MyService>();

Of course, if your service is external to Nancy it makes sense to inject it into the bootstrapper, otherwise the above is fine.

provegard avatar Jan 09 '19 12:01 provegard

It actually work in a Core 2.2 project. Just converted the project I've been working on from 2.0 to 2.2 and Nancy didn't have any issues. As a bonus, I'm noticing significantly lower CPU load after moving to 2.2 on a simple load test.

That said, it would be nice to officially get things updated (net 472, core 2.2 and all packages). I just ran through it and some updated packages have breaking changes.

tim-arheit avatar Feb 19 '19 03:02 tim-arheit