Skip to content

Port backend to .NET Core 3.1#324

Merged
johnthagen merged 11 commits intomasterfrom
dotnet-core-3.1
May 28, 2020
Merged

Port backend to .NET Core 3.1#324
johnthagen merged 11 commits intomasterfrom
dotnet-core-3.1

Conversation

@johnthagen
Copy link
Copy Markdown
Contributor

@johnthagen johnthagen commented May 22, 2020

Closes #323


This change is Reviewable

@johnthagen johnthagen self-assigned this May 22, 2020
@johnthagen johnthagen marked this pull request as draft May 22, 2020 19:32
@johnthagen
Copy link
Copy Markdown
Contributor Author

Can log in, but when trying to create a project:

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 OPTIONS https://localhost:5001/v1/projects/
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
      CORS policy execution successful.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 0.8141ms 204
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST https://localhost:5001/v1/projects/ application/json;charset=UTF-8 253
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
      CORS policy execution successful.
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[2]
      Successfully validated the token.
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful.
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'BackendFramework.Controllers.ProjectController.Post (BackendFramework)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
      Route matched with {action = "Post", controller = "Project"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Post(BackendFramework.Models.Project) on controll
er BackendFramework.Controllers.ProjectController (BackendFramework).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
      Executed action BackendFramework.Controllers.ProjectController.Post (BackendFramework) in 2.0843ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'BackendFramework.Controllers.ProjectController.Post (BackendFramework)'
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.ArgumentNullException: Value cannot be null. (Parameter 'document')
   at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName)
   at MongoDB.Driver.MongoCollectionBase`1.InsertOneAsync(TDocument document, InsertOneOptions options, Func`3 bulkWriteAsync)
   at BackendFramework.Services.ProjectService.Create(Project project) in C:\Users\User\GitHub\TheCombine\Backend\Services\ProjectApiServices.cs:line 50
   at BackendFramework.Controllers.ProjectController.Post(Project project) in C:\Users\User\GitHub\TheCombine\Backend\Controllers\ProjectController.cs:line 105
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 5.0551ms 500 text/plain

@johnthagen
Copy link
Copy Markdown
Contributor Author

johnthagen commented May 24, 2020

In this method:

public async Task<IActionResult> Post([FromBody] Project project)

project is being passed in as null. I suspect something with the Startup configuration is not correct.

On master branch, a proper Project object is passed in, which initialized fields.

@johnthagen
Copy link
Copy Markdown
Contributor Author

@johnthagen
Copy link
Copy Markdown
Contributor Author

@jasonleenaylor I think this PR is close. Everything builds and runs and passes all tests under .NET Core 3.1, but something is wrong with creating new projects (#324 (comment)), perhaps someone who's had experience porting to .NET 3.1 Core might have an idea of what is going on? Otherwise, I'll keep trying to take a look.

@jasonleenaylor
Copy link
Copy Markdown
Contributor


Backend/Startup.cs, line 153 at r5 (raw file):

            app.UseAuthentication();
            app.UseAuthorization();

So what drove this change? (I haven't looked into it yet.)

@johnthagen johnthagen mentioned this pull request May 27, 2020
@johnthagen
Copy link
Copy Markdown
Contributor Author


Backend/Startup.cs, line 153 at r5 (raw file):

Previously, jasonleenaylor (Jason Naylor) wrote…

So what drove this change? (I haven't looked into it yet.)

I was trying to follow examples I found on 3.1 porting guides. Specifically https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1#the-startup-class and https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#startup-changes. But it's very possible it's not needed as I'm not intimately familiar with this startup process yet.

@johnthagen
Copy link
Copy Markdown
Contributor Author


Backend/Startup.cs, line 153 at r5 (raw file):

Previously, johnthagen wrote…

I was trying to follow examples I found on 3.1 porting guides. Specifically https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1#the-startup-class and https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#startup-changes. But it's very possible it's not needed as I'm not intimately familiar with this startup process yet.

I tried removing the call to app.UserAuthorization(), but that causes all API calls to fail:

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST https://localhost:5001/v1/users/authenticate application/json;charset=UTF-8 41
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
      CORS policy execution successful.
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Endpoint BackendFramework.Controllers.UserController.Authenticate (BackendFramework) contains authorization metadata, but a middleware was not found that supports authorization.
Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...).
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.ThrowMissingAuthMiddlewareException(Endpoint endpoint)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 1.3494ms 500 text/plain

@johnthagen
Copy link
Copy Markdown
Contributor Author

johnthagen commented May 28, 2020

@johnthagen johnthagen requested a review from jasonleenaylor May 28, 2020 01:10
@johnthagen johnthagen marked this pull request as ready for review May 28, 2020 01:10
Copy link
Copy Markdown
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 5 files at r1, 4 of 5 files at r3, 1 of 1 files at r5, 2 of 2 files at r6.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jasonleenaylor)

@johnthagen johnthagen merged commit 628dbd2 into master May 28, 2020
@johnthagen johnthagen deleted the dotnet-core-3.1 branch May 28, 2020 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port to .NET Core 3.1

2 participants