Skip to content

Expand System.Web facade to support lightup code migrating from .NET Framework #698

@bartonjs

Description

@bartonjs

While working with a team converting from .NET Framework to .NET Core, we ran across two lightup dependency patterns involving classic ASP.NET:

  1. HttpContext.Current
if (HttpContext.Current != null) {
   ...
}

return null;
  1. HostingEnvironment.SiteName
string siteName = HostingEnvironment.SiteName;

if (!string.IsNullOrEmpty(siteName)) {
   ...
}
  1. (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

Metadata

Metadata

Assignees

Labels

area-MetaenhancementProduct code improvement that does NOT require public API changes/additionstenet-compatibilityIncompatibility with previous versions or .NET Framework

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions