toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 259 forks source link

operatingAssembly is null when using GetEntryAssembly for TestHost #289

Closed maldworth closed 4 years ago

maldworth commented 4 years ago

When using the TestHost for asp.net core (WebApplicationFactory)

This line in the RazorLightEngineBuilder gives null.

I had to Set the operating assembly to use Assembly.GetExecutingAssembly(). GetEntryAssembly() works the rest of the time (running the api normally, not using the TestHost).

jzabroski commented 4 years ago

Do you think RazorLight should utilize ASP.NET Integration Testing? If so, why? My point being, that integration testing stuff is meant to integrate an ASP.NET host without running kestrel or IIS. You are likely not using RazorLight with either Kestrel or IIS, so why are you trying to use Integration Testing framework meant to solve those problems.

toddams commented 4 years ago

@maldworth So what you propose to be a default behavior?

maldworth commented 4 years ago

2 options:

  1. Leave it as is. Close this issue and then at least anybody who encounters can search and find the reason/workaround.
  2. change the line to: var assembly = operatingAssembly ?? Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();, then hopefully nobody encounters this again.

I'll let the package maintainers/contributors decide what you prefer.

jzabroski commented 4 years ago

But can't you just call SetOperatingAssembly? I'm not trying to be critical of using ASP.NET Integration Testing framework, but for my tastes its a lot of machinery to test RazorLight. If you do find value in it, I am curious what it is so I can learn.

If you CAN call SetOperatingAssembly, AND there is value to ASP.NET Integration Testing being used, then IMHO the right approach is to update the README with guidance on doing so. Does that make sensE?

maldworth commented 4 years ago

Yes, I did call SetOperatingAssembly, works as expected. Correct, one doesn't need TestHost to test RazorLight specifically. Sounds like option 1 is the best choice here. Thanks for the quick responses!