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

RequiresAssemblyFilesAnalyzer throws InvalidCastException #2651

Closed
nagya opened this issue Feb 24, 2022 · 6 comments
Closed

RequiresAssemblyFilesAnalyzer throws InvalidCastException #2651

nagya opened this issue Feb 24, 2022 · 6 comments
Milestone

Comments

@nagya
Copy link

nagya commented Feb 24, 2022

From dotnet/roslyn#59749

Version Used: 6.0.200, bug is new in this version, i.e. was not present in 6.0.1

Steps to Reproduce:

  1. Test1.zip
  2. dotnet build

Expected Behavior:

No compile time exception and no warning.

Actual Behavior:

CSC : warning AD0001: Analyzer 'ILLink.RoslynAnalyzer.RequiresAssemblyFilesAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.TypeParameterSymbol' to type 'Microsoft.CodeAnalysis.INamedTypeSymbol'.'. 

Repro project details:

PublishSingleFile=true must be set in the project file, and both type constraints are needed in the source file.

Test1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
</Project>

Class1.cs

namespace Test1;

public abstract class Class1<T> where T : Class1<T>, new() { }
@sbomer
Copy link
Member

sbomer commented Feb 24, 2022

Duplicate of #2642

@sbomer sbomer marked this as a duplicate of #2642 Feb 24, 2022
@sbomer sbomer closed this as completed Feb 24, 2022
@nagya
Copy link
Author

nagya commented Feb 24, 2022

Duplicate of #2642

Which public release will include the fix? Can you please provide a workaround in the meanwhile?

@sbomer
Copy link
Member

sbomer commented Feb 24, 2022

I think it is set to ship with the next patch release of the 6.0.2xx SDK, @agocke can you confirm? As a workaround, you have a few options:

  • Disable the analyzer temporarily <EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
  • Update to a recent .NET 7 preview build from https://github.com/dotnet/installer (I don't think the preview1 release has the fix).
  • If you are interested I can provide instructions on using a locally-built analyzer with the fix, with the 6.0.200 SDK.

@nagya
Copy link
Author

nagya commented Feb 24, 2022

Great, thank you. Disabling temporarily with a property is a good workaround in my scenario.

@sbomer
Copy link
Member

sbomer commented Mar 2, 2022

I just realized that setting <NoWarn>$(NoWarn);AD0001</NoWarn> may be a better workaround since this appears to continue producing warnings from the analyzer for other methods (whereas by disabling it entirely might cause you to miss real issues).

@nagya
Copy link
Author

nagya commented Mar 11, 2022

Still repros in 6.0.201.

@marek-safar marek-safar added this to the .NET 6.0.x milestone Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants