format
format copied to clipboard
Changing compilation options is not supported
@JoeRobich
With the following command line, it always fails us since we have moved from .NET 6.0.403 SDK to .NET 7.0.100 SDK:
dotnet format --severity info --verbosity diagnostic Solution.sln
I have omitted sensitive information.
Fixing diagnostics...
Running 1 analyzers on Project1.
Running 1 analyzers on Project2.
Running 1 analyzers on Project3.
Running 1 analyzers on Project4.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Failed to apply code fix CSharpPreferHashDataOverComputeHashFixer for CA1850: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax'.
Complete in 754ms.
Analysis complete in 7001ms.
Complete in 14173ms.
Formatted code file 'D:\MyPath\MyFile1.cs'.
Formatted code file 'D:\MyPath\MyFile2.cs'.
Formatted code file 'D:\MyPath\MyFile3.cs'.
Formatted code file 'D:\MyPath\MyFile4.cs'.
Formatted code file 'D:\MyPath\MyFile4.cs'.
Formatted code file 'D:\MyPath\MyFile6.cs'.
Unhandled exception: System.NotSupportedException: Changing compilation options is not supported.
at Microsoft.CodeAnalysis.Workspace.CheckAllowedProjectChanges(ProjectChanges projectChanges)
at Microsoft.CodeAnalysis.Workspace.CheckAllowedSolutionChanges(SolutionChanges solutionChanges)
at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.TryApplyChanges(Solution newSolution)
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(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__4_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()
I have narrowed down the problem...
If I have a class with [DllImport], it fails.
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
public class Class1
{
[DllImport("user32.dll", SetLastError = true)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
}
}
Instead, if I apply the SYSLIB1054 IDE suggestion and turn it into this:
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
public partial class Class1
{
[LibraryImport("user32.dll", SetLastError = true)]
private static partial uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
}
}
It doesn't fail anymore...
Really, really, weird...
At least let it be of help to anyone who encounters this until it is solved.