Dotnet-Boxed / Templates

.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
https://RehanSaeed.com
MIT License
3.39k stars 489 forks source link

NullReferenceException thrown in Startup.cs, ASP.NET Core #108

Closed xorxornop closed 8 years ago

xorxornop commented 8 years ago

ConfigureServices() throws a NullReferenceException in the AddMvc(options =>) lambda in the call to AddRedirectToCanonicalUrlFilter(this.routeOptions)

this.routeOptions is null - apparently, the call to AddRouting happens after the call to AddMvc, despite their lexical ordering in the actual code (huh, that's weird. You'd think the middleware would run in set-up order...), and so this.routeOptions hasn't been given its value yet.

I built the project from latest source (6d975ae).

RehanSaeed commented 8 years ago

This seems to be behaviour that has changed from RC2 to RTM. You can have a look at the linked changeset for details of the change (Other refactoring is included).

Strangely in my testing I was getting the opposite behaviour which is why I did not catch it. After using a different machine I get the behaviour you are seeing.

I've released the fix to the project template. However, I've just realized that NWebSec is still using the old RC2 version. I've really made a hash of this release this time. You can look at https://github.com/NWebsec/NWebsec/issues/59 to see when that package gets updated and then just upgrade it.

klings commented 8 years ago

I pushed new packages just now, upgrade away. :)

xorxornop commented 8 years ago

Thanks for fixing it :) ! I'd have given a PR but I wasn't sure how you'd approach fixing it... and was myself new to both RC2 and RTM (all my projects are waiting to be migrated from RC1, once I get a proper handle on things). Glad I managed to bring it to your attention at least: odd how one machine did and and other didn't - any clue as to why? Method invocation ordering reaaaaaallly shouldn't differ between computers - right?!

@klings As an aside, thank you for making NWebsec, it's a great library.

RehanSaeed commented 8 years ago

I didn't expend any time looking into it. I added a IOptions constructor RedirectToCanonicalUrlAttribute. In the past this was not possible as you could not have multiple constructors in ASP.NET IOC. Not sure when that changed.

Thanks @klings NWebSec also updated!!!