-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
While working with a team converting from .NET Framework to .NET Core, we ran across two lightup dependency patterns involving classic ASP.NET:
- HttpContext.Current
if (HttpContext.Current != null) {
...
}
return null;- HostingEnvironment.SiteName
string siteName = HostingEnvironment.SiteName;
if (!string.IsNullOrEmpty(siteName)) {
...
}- (Theoretical) HostingEnvironment.IsHosted
Pattern 2 is used by the Microsoft.WindowsAzure.ServiceRuntime library, which prevents projects interacting with Azure's classic hosted service offering from using .NET Core (at least, if they want to interact with the service host).
We currently have a System.Web facade in the shared runtime, and I propose we increase it from one type forward to a PlatformNotSupportedException auto-generated assembly, with the following exceptions:
- HttpContext.Current should return null, rather than PNSE.
- HostingEnvironment.IsHosted should return false, rather than PNSE.
- HostingEnvironment.SiteName should return null, rather than PNSE (perhaps, generally, HostingEnvironment should behave as the "!IsHosted" case in all members that can avoid allocating new objects)
This would allow ASP.NET contextual lightup code to just execute in the "not ASP.NET" path, rather than fail with a TypeLoadException.
This extra support will not be in any ref.cs, it's only intended for the .NET Framework assembly running on .NET Core shim.
cc: @ericstj