Skip to content

[dotnet-sdk-8.0.100-preview.1.23107.4] Build with Error ASP0019,ASP0023 after retargeting to .NET 8.0 for OrchardCMS app #46642

@Junjun-zhao

Description

@Junjun-zhao

Application Name: OrchardCMS
OS: Windows10 21h2
CPU: x64
App Source Checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1746818

Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23107.4 + app (default 6.0): Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23107.4 + app (retarget 7.0): Pass
3). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23107.4 + app (retarget 8.0): Fail
4). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23112. + app (retarget 8.0): Fail

Repro steps:

  1. Copy app source to local machine.
  2. Replace net6.0 to net8.0 in src\OrchardCore.Build\Dependencies.AspNetCore.props.
  3. Build the OrchardCore.Cms.Web in Visual Studio.

Expected Result:
Build successful.

Actual Result:
image

Minimal Repro sample:
Minimal repro sample attached.
WebApplication1.zip

Repro steps:

  1. Create a default .net 7.0 AspNetCore app.
  2. Add a new Class1.cs.
  3. Add following code in Class1.cs
using Microsoft.Net.Http.Headers;

    public class Class: Controller
    {
        [Route("test")]
        public void test1(HttpContext httpContext)
        {
             httpContext.Response.Headers.Add(“”, "");
            //Change Add to Append, error will disappear
            //httpContext.Response.Headers.Append(“”, "");
        }

        [Route("test")]
        public void test2()
        {
        }
    }
  1. Build the project, there is no error in Error List windows of Visual Studio.
  2. Retarget the project to net8.0.
  3. Rebuild the project.
    Expected Result:
    Build successful.
    Actual Result:
    Build with error:
ASP0019 Use IHeaderDictionary.Append or the indexer to append or set headers. IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key.
ASP0023 Route 'test' conflicts with another action route. An HTTP request that matches multiple routes results in an ambiguous match error. Fix the conflict by changing the route's pattern, HTTP method, or route constraints.
ASP0023 Route 'test' conflicts with another action route. An HTTP request that matches multiple routes results in an ambiguous match error. Fix the conflict by changing the route's pattern, HTTP method, or route constraints.

Findings:
According to the this document: ASP0019: Suggest using IHeaderDictionary.Append or the indexer | Microsoft Learn We change the Add to Append, the warning ASP0019 disappeared.

        public void test1(HttpContext httpContext)
        {
             //httpContext.Response.Headers.Add(“”, "");
            //Change Add to Append, error will disappear
            httpContext.Response.Headers.Append(“”, "");
        }

And according to this github link: https://github.com/dotnet/dotnet/blob/ae22535816f1b667a9194e776b4ea63d2ee305f5/src/aspnetcore/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs ASP0023 is defined in this DiagnosticDescriptors.cs file, but we didn't find the relevant released doc for error ASP0023.

Dotnet Info:
.NET SDK:
 Version:   8.0.100-preview.1.23107.4
 Commit:    5a2156073c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-preview.1.23107.4\

Host:
  Version:      8.0.0-preview.1.23104.3
  Architecture: x64
  Commit:       6507a44770

.NET SDKs installed:
  8.0.100-preview.1.23107.4 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-preview.1.23105.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-preview.1.23104.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.1.23106.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions