-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MVC assumes IHostingEnvironment.ApplicationName contains the entry point assembly's name #6685
Comments
The doc does needs an update. We should remove that configuring the application name to something arbitrary. |
@MisterGoodcat would you be able to create a PR or draft the changes needed? |
I'll note on dotnet/AspNetCore.Docs#1870 that it might surface setting @MisterGoodcat If u just want to PR a one-liner to cover this, you don't need to sweat the full dotnet/AspNetCore.Docs#1870 ... I added it to a list of backlog issues that I hope to address in the coming few weeks. Just note in the issue comment: |
@davidfowl Are u saying "remove" as in "remove it completely" or as in "just remove the arbitrary value in setting it"? How about something like ... new WebHostBuilder()
.UseSetting("applicationName", "MyDependencyContextAssemblyName") ... along with a combined note based on current language,
|
Remove it completely. |
I'll patch it now. |
Hi and sorry for the late reply, I was out of town for a few days. Do you still need anything from me? |
@MisterGoodcat The |
Some parts of MVC seem to assume that
IHostingEnvironment.ApplicationName
actually contains an assembly name.The situation:
ApplicationName
property so it matches whatever the actual implementation is handed off to (an application-level project/assembly).Typically these applications have no views (only RESTful APIs), so we didn't come across any issues until now. But this one has a minimal UI too, and the result was a FileNotFoundException buried deep in a stack trace down to the RazorViewCompiler.
It took some digging in the sources to find that the CSharp compiler tries to load an assembly based on that property, and looking further revealed that there are other places in the code base, for example around the assembly parts discovery, that rely on IHostingEnvironment.ApplicationName returning an assembly name.
The good news is that today I learned about the concept of dependency context and its compilation options. The bad side of this was that it was super-non-obvious what happens and that it took too long to understand what the actual problem is.
"ApplicationName" is really bad semantics for this, but I guess that's baked now and cannot be changed. At least make the documentation very clear on what the purpose/intention in the context of MVC is, so people don't change it randomly to "nicer" things. The documentation of IHostingEnvironment simply says it's set to entry point assembly name, but the documentation on hosting fundaments says you can happily change this and even shows (bad) sample code of how to set it to something like "MyApp". Btw. there seems to exist an older issue for that (milestone 1.0.1) that apparently never had been completed.
The text was updated successfully, but these errors were encountered: