question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues switching from .NET SDK 6.0.x to 7.0.100

See original GitHub issue

As a first step in migrating a .NET desktop (WPF,WinForms) application from .NET 6.0 to .NET 7.0 we have been simply switching to the new .NET SDK 7.0.100 by e.g. defining:

{
  "sdk": {
    "version": "7.0.100",
    "rollForward": "latestFeature",
    "allowPrerelease": false
  }
}

where version before was say 6.0.403. No other changes were made. However, this caused two sets of issues and we are wondering if these were expected, why and how to handle them properly. The two issues are:

  • Change in behavior when defining <PublishSingleFile>true</PublishSingleFile> in csproj
  • Change in code analysis rules causing errors

PublishSingleFile

This was a head scratcher. The solution in question will build an AnyCPU exe that works and runs on both x86 and x64. However, when switching to .NET SDK 7.0.100 this would not work. Either tests would simply not run with issues around bad format for the exe assembly or similar. Or if trying to run the exe project e.g. using F5 in visual studio this would simply crash upon start before anything with something like The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core."... code 2147516546 (0x80008082). As far as I can tell it turns out behavior has changed (silently) for PublishSingleFile so this now forces a RuntimeIdentifier (RID) to be set without any warning or similar. This causes the “format” of the output assembly to become platform specific e.g. win-x64 and hence trying to run x86 tests based on it will fail. Changing this definition to:

    <PublishSingleFile Condition="'$(RuntimeIdentifier)' != ''">true</PublishSingleFile>

resolved the issue. Guessing you should simply not define these options in csproj in the future if you have project that you want to build as Any CPU but instead do that only on command line when actually doing publish. Which means these often become redundantly defined.

Code Analysis Changes

This we don’t understand. We have the following defined in Directory.Build.props with an accompanying .editorconfig next to sln at root of git repo.

    <AnalysisLevel>latest</AnalysisLevel>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>

This compiled fine with zero errors using .NET 6.0 SDK. Switching to .NET SDK 7.0.100 and we had to define the following NoWarn to the solution building without errors. Note that the set of CAxxxx errors reported in VS and on command line are different this is the union of both to get both building.

    <NoWarn>
      $(NoWarn);
      CA1000;CA1001;CA1002;CA1003;CA1005;CA1008;CA1010;CA1012;CA1017;
      CA1021;CA1024;CA1028;CA1030;CA1031;CA1032;CA1036;
      CA1040;CA1043;CA1044;CA1045;CA1051;CA1052;CA1060;CA1062;CA1063;CA1065;CA1067;
      CA1304;CA1305;CA1307;CA1309;CA1310;CA1311;
      CA1401;CA1501;CA1506;CA1508;
      CA1707;CA1710;CA1711;CA1716;CA1720;CA1721;CA1724;CA1725;
      CA1802;CA1805;CA1810;CA1813;CA1814;CA1815;CA1816;CA1819;
      CA1820;CA1823;CA1825;CA1826;CA1829;CA1838;CA1850;CA1851;CA1852;
      CA2000;CA2007;CA2008;CA2101;CA2201;CA2208;CA2213;CA2214;CA2217;CA2225;CA2227;
      CA5392;CA5394
    </NoWarn>

that’s a lot of new code analysis rules suddenly causing errors and this seems off, is this expected?

We would also the have expected to be able to set AnalysisLevel to 6.0 and get the 6.0 SDK behavior but this had no effect at all. Was this not the intended function of this property?

    <AnalysisLevel>6.0</AnalysisLevel>

Further technical details

  • Include the output of dotnet --info
 dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  3.1.425 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  5.0.413 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]
  6.0.111 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.306 [C:\Program Files\dotnet\sdk]
  6.0.400 [C:\Program Files\dotnet\sdk]
  6.0.403 [C:\Program Files\dotnet\sdk]
  7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version

Visual Studio 17.5.0 Preview 1.0

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:3
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
nietrascommented, Nov 29, 2022

A little side note also discovered a rule CA1852 that is “undocumented” below link will fail can can’t google it:

https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1852

Severity	Code	Description	Project	File	Line	Suppression State
Error	CA1852	Type 'XYZ' can be sealed because it has no subtypes in its containing assembly and is not externally visible WWW

and I hit the top-level statement issue here too:

https://github.com/dotnet/runtime/issues/78270 “Type ‘Program’ can be sealed because it has no subtypes in its containing assembly and is not externally visible”

Read more comments on GitHub >

github_iconTop Results From Across the Web

SDK Resolver Failure - Net 7 - Net 6
Just downloaded and installed SDK Net 7.0.100 and it broke existing applications and they won't load any more in VS 2022 or Rider....
Read more >
NETSDK1045: The current .NET SDK does not support ...
This error occurs when the build tools can't find the version of the .NET SDK that's needed to build a project. This is...
Read more >
Could not find a suitable .NET 6 runtime version matching ...
NET 6 runtime version matching SDK version: 7.0.100 #2719 ... I encountered this issue after upgrading FAKE from 5.23.1 to 6.0.0:.
Read more >
Net Core/MSBuild Tooling not finding right version
Error : Version 3.1.401 of the .NET Core SDK requires at least version 16.7.0 of MSBuild. The current available version of MSBuild is...
Read more >
Incompatible versions of Mono MSBuild and .NET Core ...
NET Core SDK are incompatible on Linux and macOS. ... In case, you use mono 5.x and you want to continue using it,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found