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

MarshallingAttributeAnalyzers throws InvalidCastException #75681

Closed
idigra opened this issue Sep 15, 2022 · 5 comments · Fixed by #75727
Closed

MarshallingAttributeAnalyzers throws InvalidCastException #75681

idigra opened this issue Sep 15, 2022 · 5 comments · Fixed by #75727
Assignees
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature

Comments

@idigra
Copy link

idigra commented Sep 15, 2022

Description

NativeMarshallingAttributeAnalyzer and CustomMarshallerAttributeAnalyzer are throwing exceptions when building the runtime repo.

Reproduction Steps

I upgraded an existing ADO pipeline to use .NET 7 RC 1 and it started to fail.
I have no idea what configuration in repo is relevant for repro, I'll be happy to share more details and link to pipeline as needed.

Expected behavior

No errors

Actual behavior

##[error]CSC(0,0): Error AD0001: Analyzer 'Microsoft.Interop.Analyzers.NativeMarshallingAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.
7>CSC : error AD0001: Analyzer 'Microsoft.Interop.Analyzers.NativeMarshallingAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'. [D:\a_work\10\s\src\Product\UITester.Mac\Microsoft.Mashup.Client.UITester.Mac.csproj]
##[error]CSC(0,0): Error AD0001: Analyzer 'Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.
7>CSC : error AD0001: Analyzer 'Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'. [D:\a_work\10\s\src\Product\UITester.Mac\Microsoft.Mashup.Client.UITester.Mac.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Seems similar to #72622 , but this time with InvalidCastException instead of InvalidOperationException.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 15, 2022
@jkoritzinsky
Copy link
Member

If you can figure out which syntax the analyzer is inspecting when it fails, that would be a good minimal repro that we could use to diagnose and fix the failure.

@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels Sep 15, 2022
@ghost
Copy link

ghost commented Sep 15, 2022

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

NativeMarshallingAttributeAnalyzer and CustomMarshallerAttributeAnalyzer are throwing exceptions when building the runtime repo.

Reproduction Steps

I upgraded an existing ADO pipeline to use .NET 7 RC 1 and it started to fail.
I have no idea what configuration in repo is relevant for repro, I'll be happy to share more details and link to pipeline as needed.

Expected behavior

No errors

Actual behavior

##[error]CSC(0,0): Error AD0001: Analyzer 'Microsoft.Interop.Analyzers.NativeMarshallingAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.
7>CSC : error AD0001: Analyzer 'Microsoft.Interop.Analyzers.NativeMarshallingAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'. [D:\a_work\10\s\src\Product\UITester.Mac\Microsoft.Mashup.Client.UITester.Mac.csproj]
##[error]CSC(0,0): Error AD0001: Analyzer 'Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.
7>CSC : error AD0001: Analyzer 'Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'. [D:\a_work\10\s\src\Product\UITester.Mac\Microsoft.Mashup.Client.UITester.Mac.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Seems similar to #72622 , but this time with InvalidCastException instead of InvalidOperationException.

Author: idigra
Assignees: -
Labels:

area-System.Runtime.InteropServices, untriaged, source-generator

Milestone: -

@jkoritzinsky jkoritzinsky added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 15, 2022
@ghost
Copy link

ghost commented Sep 15, 2022

This issue has been marked needs-author-action and may be missing some important information.

@jkoritzinsky jkoritzinsky removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 15, 2022
@jkoritzinsky
Copy link
Member

We spoke offline and determined that the failure case is an attribute on the return type of a delegate:

[return: Attr]
delegate int X();

In this case, the containing symbol is a type, not a method.

@jkoritzinsky jkoritzinsky self-assigned this Sep 15, 2022
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this issue Sep 15, 2022
Fix two customer-discovered edge cases that were causing analyzer crashes.

Fixes dotnet#75681
Fixes dotnet#75706
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 15, 2022
github-actions bot pushed a commit that referenced this issue Sep 15, 2022
Fix two customer-discovered edge cases that were causing analyzer crashes.

Fixes #75681
Fixes #75706
carlossanlop pushed a commit that referenced this issue Sep 16, 2022
Fix two customer-discovered edge cases that were causing analyzer crashes.

Fixes #75681
Fixes #75706

Co-authored-by: Jeremy Koritzinsky <jekoritz@microsoft.com>
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Sep 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants