简体   繁体   中英

Why does roslyn throw a RCS1110 warning in ASP.NET C# class files?

We are rebuilding our code structures in VS 2017 from the ground up and our lead has determined that we need to commit all of our code with no compile errors or warnings in Code Analysis. As our old Code base is .net 2.0 that was last updated to .net 3.5 for some minor additions to our sites, we are incorporating tools and features in VS that are new to most of us. On an ASP.NET Web application, when adding a new aspx page to a project, it auto configures the code behind, sets the Inherits value in the markup and creates a public partial class as it always has.

public partial class webforms_divTableTest : System.Web.UI.Page
{
}
<%@ Page Language="C#" MasterPageFile="~/MenuMaster.master" AutoEventWireup="true" CodeFile="divTableTest.aspx.cs" Inherits="webforms_divTableTest" %>

As soon as I build the project it throws this warning on every page set:

RCS1110 Declare 'webforms_divTableTest' inside namespace.   

This leaves me with a few questions:

  1. Why isn't this set up in the templates in the first place?
  2. What is the point of this on a conventional "all-in-one form" site (eg not templated or segmented into more files than exist normally with a masterpages site)?
  3. Why does Quick Action fixer add the namespace declaration in a way that breaks all of the code in the C# file?
  4. How should I add/fix the namespace so that my cs code still works when referenced in the aspx file?

Apparently I can do this:

namespace divTableTest
{
  public partial class webforms_divTableTest : System.Web.UI.Page
  {
  }
}

and change my aspx to:

inherits="divTableTest.webforms_divTableTest"

The compiler and Code Analysis are no longer complaining. The rest of my questions still stand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM