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
The IDE0022 analyzer mistakenly suggests/fixes code that includes preprocessor directives without correctly handling conditional code. Consider the following example code that demonstrates the concern:
usingSystem.Diagnostics;internalsealedclassExample{publicstaticintGetRandomNumber()=>
#if SOME_DIRECTIVEif(Debugger.IsAttached){Debugger.Break();}
return Random.Shared.Next();
#endif
new Random().Next();}
Define the SOME_DIRECTIVE preprocessor directive.
#define SOME_DIRECTIVE
usingSystem.Diagnostics;internalsealedclassExample{publicstaticintGetRandomNumber()=>
#if SOME_DIRECTIVEif(Debugger.IsAttached){Debugger.Break();}
return Random.Shared.Next();
#endif
new Random().Next();}
Expected behavior
It shouldn't even suggest this as a fix since the return code is conditional via preprocessor directives.
Actual behavior
It doesn't compile after the preprocessor directive is defined (or set).
Regression?
No response
Known Workarounds
No response
Configuration
.NET 7.0
Microsoft Visual Studio Enterprise 2022
Version 17.8.0 Preview 1.0
VisualStudio.17.Preview/17.8.0-pre.1.0+34004.107
Microsoft .NET Framework
Version 4.8.09032
Installed Version: Enterprise
Architecture Diagrams and Analysis Tools 00476-80000-00000-AA395
Microsoft Architecture Diagrams and Analysis Tools
Visual C++ 2022 00476-80000-00000-AA395
Microsoft Visual C++ 2022
ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools
ASA Service Provider 1.0
ASP.NET and Web Tools 17.8.92.59062
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.8.92.59062
Azure App Service Tools v3.0.0
Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 17.8.92.59062
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 4.8.0-1.23377.4+692d17e98436dfde74109aefe78f3507ae6c5b36
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Extensibility Message Bus 1.4.36 (main@1d5b5ab)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
GitHub Copilot 1.100.0.0 (v1.100.0.0@6ff082509)
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.
GitHub Copilot Agent 1.100.306 (v1.100.0)
Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query
Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics
Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Mono Debugging for Visual Studio 17.8.2 (478da90)
Support for debugging Mono processes with Visual Studio.
Node.js Tools 1.5.50712.1 Commit Hash:7dd535af036092a55334b9c86208a8ed6dc876cd
Adds support for developing and debugging Node.js apps in Visual Studio
NuGet Package Manager 6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.8.1.2337707+b468e7a28394b4ed4bf9faa839eef13389fb4bb8
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools 17.8.1.0
Microsoft SQL Server Data Tools
Syntax Visualizer 1.0
An extension for visualizing Roslyn SyntaxTrees.
ToolWindowHostedEditor 1.0
Hosting json editor into a tool window
TypeScript Tools 17.0.20731.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.8.0-1.23377.4+692d17e98436dfde74109aefe78f3507ae6c5b36
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.8.0-beta.23371.1+eb5d11d8baf35672ddc818b63c55a2b7a03b087e
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
VisualStudio.DeviceLog 1.0
Information about my package
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info
Xamarin 17.8.0.57 (main@01c1a2c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 17.8.0.6 (remotes/origin/d17-8@8ad896476f)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 17.8.5 (0dabaf0)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
This also seems to be a with the IDE0074 Compound assignment analyzer as well, in that if there are preprocessor directives, it doesn't work as expected.
Description
The IDE0022 analyzer mistakenly suggests/fixes code that includes preprocessor directives without correctly handling conditional code. Consider the following example code that demonstrates the concern:
After applying IDE0022:
This code will cause the IDE0022 analyzer to suggest the use of expression-bodied members when that's configured as the preference for the project.
After the suggestion is applied, and assuming that at some point the preprocessor directive is set, the code will not compile:
For the sake of argument, let's just define
SOME_DIRECTIVE
inline to see the affect:Reproduction Steps
Create a simple class, with a simple method that uses a preprocessor directive to conditionally return a value.
Apply IDE0022.
Define the
SOME_DIRECTIVE
preprocessor directive.Expected behavior
It shouldn't even suggest this as a fix since the
return
code is conditional via preprocessor directives.Actual behavior
It doesn't compile after the preprocessor directive is defined (or set).
Regression?
No response
Known Workarounds
No response
Configuration
.NET 7.0
Microsoft Visual Studio Enterprise 2022
Version 17.8.0 Preview 1.0
VisualStudio.17.Preview/17.8.0-pre.1.0+34004.107
Microsoft .NET Framework
Version 4.8.09032
Installed Version: Enterprise
Architecture Diagrams and Analysis Tools 00476-80000-00000-AA395
Microsoft Architecture Diagrams and Analysis Tools
Visual C++ 2022 00476-80000-00000-AA395
Microsoft Visual C++ 2022
ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools
ASA Service Provider 1.0
ASP.NET and Web Tools 17.8.92.59062
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.8.92.59062
Azure App Service Tools v3.0.0
Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 17.8.92.59062
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 4.8.0-1.23377.4+692d17e98436dfde74109aefe78f3507ae6c5b36
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Extensibility Message Bus 1.4.36 (main@1d5b5ab)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
GitHub Copilot 1.100.0.0 (v1.100.0.0@6ff082509)
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.
GitHub Copilot Agent 1.100.306 (v1.100.0)
Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query
Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics
Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Mono Debugging for Visual Studio 17.8.2 (478da90)
Support for debugging Mono processes with Visual Studio.
Node.js Tools 1.5.50712.1 Commit Hash:7dd535af036092a55334b9c86208a8ed6dc876cd
Adds support for developing and debugging Node.js apps in Visual Studio
NuGet Package Manager 6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.8.1.2337707+b468e7a28394b4ed4bf9faa839eef13389fb4bb8
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools 17.8.1.0
Microsoft SQL Server Data Tools
Syntax Visualizer 1.0
An extension for visualizing Roslyn SyntaxTrees.
ToolWindowHostedEditor 1.0
Hosting json editor into a tool window
TypeScript Tools 17.0.20731.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.8.0-1.23377.4+692d17e98436dfde74109aefe78f3507ae6c5b36
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.8.0-beta.23371.1+eb5d11d8baf35672ddc818b63c55a2b7a03b087e
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
VisualStudio.DeviceLog 1.0
Information about my package
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info
Xamarin 17.8.0.57 (main@01c1a2c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 17.8.0.6 (remotes/origin/d17-8@8ad896476f)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 17.8.5 (0dabaf0)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 13.2.1.2 (d17-5/a8a26c7)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
Xamarin.iOS and Xamarin.Mac SDK 16.4.0.5 (191fe02ea)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Other information
No response
The text was updated successfully, but these errors were encountered: