Closed martincostello closed 3 months ago
It works if I add <PublishAot>true</PublishAot>
to my project file, so I guess it's just a bug in the reflection-based code paths.
looking
Seems it's something to do with initialization of injected properties (in your case the IOptions<SiteOptions>
. Hopefully an easy fix.
Something else I've literally just run into which is quite the Picard-face-palm moment that's also related to injection.
I've been trying to work out why I couldn't get injection working in a different project ("Can't inject because there's no service provider"), and after debugging through my project into yours I realised via some copy-pasta that I'd forgotten to get my top level slice to use @inherits RazorSliceHttpResult<MyModel>
and instead I was doing @inherits RazorSlice<MyModel>
, and then that ends up never assigning an HttpContext
and then stuff all goes š„.
This one's clearly my fault, but it did make me wonder, is there something missing for the code path when razorSlice
isn't a IRazorSliceHttpResult
that should be catering for that?
@martincostello that should be fixed in new version as it should detect and wrap it now. If not, let me know!
I have a fix for this issue coming now.
I only forked the repo just now, so I think whatever that fix was didn't work. I'll try and debug it a bit further with my mistake back in and see what I find.
Haven't gotten to the bottom of exactly what is wrong yet, but it looks like when I use a layout slice, when CopySliceState()
runs the source slice hasn't had the HttpContext assigned yet, so it just copies null to null, and then the layout fails whenever I have some code running that needs it.
Are you using the Results.Extensions.RazorSlice<MySlice>
extension method?
Results.Extensions.RazorSlice<MySlice, MyModel>(model);
OK I figured it out, fix for that coming too I hope.
OK pushed. Just waiting for ingestion at nuget.org: https://www.nuget.org/packages/RazorSlices/0.8.1
Cheers for the fast around! I'll try it out once it pops up.
Yep - both things I stumbled into fixed in 0.8.1 - š„
I just saw you'd shipped support for layout and sections (and AoT š), so thought I'd try migrating one of my simple Razor Pages sites over to use RazorSlices.
Now I'm sure I've done something stupid (I'm like 15 mins in), but I got the following exception trying to render my first slice at runtime:
The slice, the
_ViewImports.cshtml
and the code to render it are:The
int
is just a placeholder as I try and build things up as I migrate, it wouldn't be what I'd really use.There's a good chance I've made a mistake somewhere and/or not read the documentation properly, but the exception message is certainly confusing to guide me to whatever that is to fix it.