C#:s3443 Is Wrong

‘typeof(x).GetType()’ returns ‘System.RuntimeType’, not ‘System.Type’ like the rule claims.

As ‘System.RuntimeType’ is not able to be directly referenced in source code, ‘typeof(Type).GetType()’ is necessary get to it, which triggers the rule.

Likely the basics of the rule still makes sense, as it’s unlikely users actually want to be dealing with ‘System.RuntimeType’ but the rule description needs to be corrected. An exception should be made for ‘typeof(Type).GetType()’, as it explicitly means I want ‘System.RuntimeType’. Potentially there are other intentional cases?

Hi @Werebunny,

Thanks for pointing this out. I’ve added an issue to fix the documentation and to add an exception for ‘typeof(Type).GetType()’.

You can follow the progress here: Improve S3443: Add exception for ‘typeof(Type).GetType()’ and update rule spec to add exception · Issue #4201 · SonarSource/sonar-dotnet · GitHub

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.