Skip to content

dotnet format broken in SDK 10.0.200 - TypeInitializationException in Microsoft.Build.Shared.XMakeElements #53383

@Xorpio

Description

@Xorpio

Describe the bug

dotnet format crashes with System.TypeInitializationException in Microsoft.Build.Shared.XMakeElements when attempting to format any C# project or solution after updating to .NET SDK 10.0.200. This affects all project types including legacy .NET Framework 4.7.2, modern SDK-style projects, and solution files. The issue occurs with both Visual Studio 2022 (17.14) and Visual Studio 2026 (18.4).

Impact: This is a critical regression that completely blocks all dotnet format workflows globally, affecting pre-commit hooks, CI/CD pipelines, and local development.

To Reproduce

Minimal repro:

  1. Install .NET SDK 10.0.200
  2. Have Visual Studio 2022 (17.14+) or Visual Studio 2026 (18.4+) installed
  3. Run dotnet format on any of the following:
    • A solution file: dotnet format MySolution.sln --verify-no-changes
    • A legacy .NET Framework project: dotnet format LegacyProject.csproj --verify-no-changes
    • An SDK-style project: dotnet format ModernProject.csproj --verify-no-changes

Result: All commands crash with TypeInitializationException

Test Matrix:

Project Type VS 2022 MSBuild (17.14) VS 2026 MSBuild (18.4)
Solution (.sln) ❌ TypeInitializationException ⏱️ Hangs indefinitely
.NET Framework 4.7.2 (old .csproj) ❌ TypeInitializationException ❌ Restore operation failed
SDK-style project (.NET 6+) ❌ TypeInitializationException ❌ TypeInitializationException

Workarounds attempted:

  • ❌ Specifying $env:MSBUILD_EXE_PATH to different MSBuild versions
  • ❌ Testing with individual project files vs solution files
  • dotnet build also fails with similar MSBuild workspace errors
  • ✅ Regular msbuild.exe builds work fine (issue is specific to Roslyn workspace loader)

No workaround found.

Exceptions (if any)

Unhandled exception: Microsoft.CodeAnalysis.MSBuild.RemoteInvocationException: 
An exception of type System.TypeInitializationException was thrown: 
The type initializer for 'Microsoft.Build.Shared.XMakeElements' threw an exception.

   at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeCoreAsync(Int32 targetObject, String methodName, List`1 parameters, Type expectedReturnType, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeAsync[T](Int32 targetObject, String methodName, List`1 parameters, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.RemoteBuildHost.LoadProjectFileAsync(String projectFilePath, String languageName, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.DoOperationAndReportProgressAsync[TResult](ProjectLoadOperation operation, String projectPath, String targetFramework, Func`1 doFunc)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress`1 progress, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceLoader.LoadAsync(String solutionOrProjectPath, WorkspaceType workspaceType, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.OpenMSBuildWorkspaceAsync(String solutionOrProjectPath, WorkspaceType workspaceType, Boolean noRestore, Boolean requiresSemantics, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)

Further technical details

details of dotnet --info

.NET SDK:
 Version:           10.0.200
 Commit:            40cd698e5c
 Workload version:  10.0.200-manifests.b7278506
 MSBuild version:   18.3.0-release-26119-122+40cd698e5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.200\

.NET workloads installed:
 [wasm-tools]
   Installation Source: VS 18.4.11605.240
   Manifest Version:    10.0.104/10.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.workload.mono.toolchain.current\10.0.104\WorkloadManifest.json
   Install Type:        Msi

Configured to use workload sets when installing new manifests.
No workload sets are installed.

Host:
  Version:      10.0.4
  Architecture: x64
  Commit:       80d3e14f5e

.NET SDKs installed:
  9.0.312 [C:\Program Files\dotnet\sdk]
  10.0.104 [C:\Program Files\dotnet\sdk]
  10.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

IDE versions:

  • Visual Studio 2022 Enterprise - Version 17.14.37027.9 (MSBuild 17.14.40.60911)
  • Visual Studio 2026 Community - Version 18.4.11605.240 (MSBuild 18.4.0.7901)

dotnet format version:

  • 10.0.200-servicing.26119.122+40cd698e5cfb2d90f436889726ee01f48d99f3ab

Additional Context:

  • This appears to be a breaking change in .NET SDK 10.0.200 / MSBuild 18.3.0
  • The Microsoft.CodeAnalysis.MSBuild.RemoteInvocationException wraps the actual TypeInitializationException occurring in Microsoft.Build.Shared.XMakeElements
  • Regular msbuild.exe builds work fine - issue is specific to Roslyn's MSBuild workspace loader
  • This regression blocks all users with .NET SDK 10.0.200 from using dotnet format
  • Affects pre-commit hooks, CI/CD pipelines, and all automated formatting workflows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions