Why are unsupported System.Web classes still accessible in .Net Standard?

104 Views Asked by At

I am nearing the end of the task of porting a large library project from .Net Framework 4.7.2 to .Net Standard 2.0. This library previously used the System.Web namespace, but since most of that namespace is not supported in .Net Standard, I've refactored or removed all of the System.Web stuff. Now that the update is complete and the solution is working as expected, I found that I can still write code that accesses the parts of System.Web that are not supported in .Net Standard. I expected that this wouldn't be allowed. I assumed the unsupported classes & enums & such would simply not be present or accessible. If I create a .Net 6 or 8 project, I see that HttpUtility is the only class available in System.Web. Why is a .Net Standard project different? In my .Net Standard 2.0 library project, not only is everything accessible (System.Web.Caching, System.Web.Security, etc), but I can write code and compiles without even a warning. This seems problematic as other developers could potentially write code that accesses unsupported parts of the System.Web namespace and deploy that code. I have created a code analyzer (DiagnosticAnalyzer) package to prevent that from happening, but I'm still confused why this is necessary. Aside from HttpUtility, why is the rest of System.Web accessible in .Net Standard?

1

There are 1 best solutions below

1
user15890395 On

I found the issue. I had a reference to Microsoft.AspNetCore.SystemWebAdapters. Removing that resolves the issue.