Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting UA0002 with no clear explanation why and what to fix #1102

Closed
Tracked by #11
dziedrius opened this issue Apr 14, 2022 · 2 comments · Fixed by #1291
Closed
Tracked by #11

Getting UA0002 with no clear explanation why and what to fix #1102

dziedrius opened this issue Apr 14, 2022 · 2 comments · Fixed by #1291
Assignees
Labels
area:Analyze community reported Triaged Label to show that UA team has triaged this issue.

Comments

@dziedrius
Copy link

Describe the bug

When running upgrade assistant get following:

Diagnostic UA0002 with the message This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent. generated

And it is not clear, what type, why. I've scanned through migration guide and could not find anything related.

To Reproduce

Create new web project:

dotnet new web

and add class into Program.cs:

public class OverrideSuccessResponseCode : ResultFilterAttribute, IApiResponseMetadataProvider
{
    public int StatusCode { get; }
    public Type Type { get; } = typeof(void);

    public OverrideSuccessResponseCode(int statusCode) => StatusCode = statusCode;

    public override void OnResultExecuted(ResultExecutedContext context)
    {
        if (context.HttpContext.Response.StatusCode == (int)HttpStatusCode.OK)
        {
            context.HttpContext.Response.StatusCode = StatusCode;
        }
    }
    void IApiResponseMetadataProvider.SetContentTypes(MediaTypeCollection contentTypes)
    {
    }
}

After running

upgrade-assistant.exe analyze .\test-upgrade.csproj

You should get:

PS C:\temp\test-upgrade> upgrade-assistant.exe analyze .\test-upgrade.csproj
-----------------------------------------------------------------------------------------------------------------
Microsoft .NET Upgrade Assistant v0.3.310801+057ffba0656270dc5d83c015748ac56daed55886

We are interested in your feedback! Please use the following link to open a survey: https://aka.ms/DotNetUASurvey
-----------------------------------------------------------------------------------------------------------------

[08:26:03 INF] Loaded 6 extensions
[08:26:03 INF] Using MSBuild from C:\Program Files\dotnet\sdk\6.0.201\
[08:26:03 INF] Using Visual Studio install from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional [v16]
[08:26:05 INF] Writing output to C:\temp\test-upgrade\AnalysisReport.sarif
[08:26:05 INF] Recommending executable TFM net6.0 because the project builds to an executable
[08:26:06 INF] Reference to .NET Upgrade Assistant analyzer package >(Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.3.310801) needs to be added
[08:26:07 INF] Reference to Newtonsoft package (Microsoft.AspNetCore.Mvc.NewtonsoftJson, version 6.0.4) needs to be added
[08:26:07 INF] Running analyzers on test-upgrade
[08:26:08 INF] Identified 1 diagnostics in project test-upgrade
[08:26:08 INF] Diagnostic UA0002 with the message This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent. generated

upgrade-asstant.clef file contains line:

{"@t":"2022-04-14T05:26:08.3477296Z","@mt":"Diagnostic {Id} with the message {Message} generated","Id":"UA0002","Message":"This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent.","SourceContext":"Microsoft.DotNet.UpgradeAssistant.Steps.Source.DiagnosticAnalyzerResultProvider"}

AnalysisReport.sarif file contains:

{
      "tool": {
        "driver": {
          "name": "API Upgradability",
          "semanticVersion": "0.3.310801",
          "informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview",
          "rules": [
            {
              "id": "UA0002",
              "fullDescription": {
                "text": "Types should be upgraded"
              },
              "helpUri": "about:blank"
            }
          ]
        }
      },
      "results": [
        {
          "ruleId": "UA0002",
          "message": {
            "text": "This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent."
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///C:/temp/test-upgrade/Program.cs"
                },
                "region": {
                  "startLine": 20
                }
              }
            }
          ]
        }
      ],
      "columnKind": "utf16CodeUnits"
    }

From this information it is not clear what and how to fix.
Running assistant with upgrade command does not change source in any way.

@sunandabalu sunandabalu added community reported Triaged Label to show that UA team has triaged this issue. area:Analyze labels Apr 26, 2022
@sunandabalu
Copy link
Member

@dziedrius Thanks for the issue, makes sense we will look into making this warning more actionable.

@rmjoia
Copy link

rmjoia commented May 19, 2022

I'm also getting that error but only on VSCode, doesn't show on VS2022 (17.1.6)

I also tried using the dotnet upgrade-assistant and the *.sarif file generated points to the same issue. We're talking about plain old controllers and public methods being flagged with that warning

"ruleId": "UA0002", "message": { "text": "This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent." }

any ideas of what this is about would be very appreciated.

@mjrousos mjrousos self-assigned this Aug 31, 2022
mjrousos added a commit that referenced this issue Sep 9, 2022
* Display analyzer message in analysis reports rather than description
* Fix how packages are retrieved for non-SDK projects
* Fix package loader to check more thoroughly for TFM compatbility

Fixes #1102
Fixes #1034
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Analyze community reported Triaged Label to show that UA team has triaged this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants