I created a toy project for checking out the latest .NET 7 (preview-5) and the regex code generation. It worked great, so I applied the same changes to an existing project (not for production, but for personal productivity). For some reason, I’m getting these warnings:
CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.ValidateFormatString.CSharpValidateFormatStringDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll : Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Das System kann die angegebene Datei nicht finden..
CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.UseUTF8StringLiteral.UseUTF8StringLiteralDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll : Exception has been thrown by the target of an invocation..
CS8033 The assembly C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.dll does not contain any analyzers.
The text Das System kann die angegebene Datei nicht finden.. translates to “The system cannot find the specified file,” but this is a DeepL translation and the actual English error message may be different.
Of the first two, it’s over 200 similar-spirited them with differing analyzers.
The toy project was a console application, the problematic project is a Windows Forms application, if this is somehow relevant. This is the – I believe – relevant part of the .csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>disable</ImplicitUsings>
<AnalysisLevel>latest-all</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Svg" Version="3.4.2" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>1</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<WarningLevel>1</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
</Project>
I also tried commenting-out the Svg dependency and the code that uses it. That changed nothing notably.
And, for comparison and completion, this is the .csproj
file of the toy project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
I do not understand why the analyzers aren’t found. The DLLs are definitely there. I suspect that it’s the Version=4.3.0.0
part, but I have no idea what that version refers to, which one would be correct and where I’d specify that.
One answer I found told me to use <TargetFrameworks>net7.0-windows;netstandard-2.0</TargetFrameworks>
(or something very similar), but that didn’t work.
I’ve searched the internet for a few hours now, and it appears that no one has had this problem so far; solutions for similar issues didn’t work for me.
Edit (2022-12-17): The problem disappeard after updating VS at a certain version.