You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analyzer 'Roslynator.CSharp.Analysis.UseEnumFieldExplicitlyAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'System.Int32' to type 'System.SByte'
#1262
Closed
jroessel opened this issue
Nov 21, 2023
· 0 comments
· Fixed by #1264
Steps to Reproduce: Have an enum that derives from sbyte (other types may exhibit this problem as well), e.g. the following code, and have a cast of a numeric constant to that enum type somewhere.
Analyzer 'Roslynator.CSharp.Analysis.UseEnumFieldExplicitlyAnalyzer' threw an exception of type 'System.InvalidCastException' withmessage 'Unable to cast objectof type 'System.Int32' to type 'System.SByte'.'.Exception occurred with following context:Compilation:ConsoleApp5SyntaxTree: C:\Users\roessel\source\repos\ConsoleApp5\Program.cs
SyntaxNode:(TestEnum)2[CastExpressionSyntax]@[66..78)(1,35)-(1,47)
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.SByte'.
at Roslynator.ConvertHelpers.ConvertToUInt64(Objectvalue,SpecialTypenumericType)
at Roslynator.CSharp.Analysis.UseEnumFieldExplicitlyAnalyzer.AnalyzeCastExpression(SyntaxNodeAnalysisContextcontext)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__49`1.<ExecuteSyntaxNodeAction>b__49_0(ValueTuple`2data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzeranalyzer, Action`1analyze,TArgargument, Nullable`1info,CancellationTokencancellationToken)
Expected Behavior:
A suggestion to use the actual enum constant instead of the analyzer crashing.
The text was updated successfully, but these errors were encountered:
Product and Version Used:
Steps to Reproduce: Have an enum that derives from
sbyte
(other types may exhibit this problem as well), e.g. the following code, and have a cast of a numeric constant to that enum type somewhere.Actual Behavior:
Expected Behavior:
A suggestion to use the actual enum constant instead of the analyzer crashing.
The text was updated successfully, but these errors were encountered: