[Bug]: Build fails for primary contructor, but not classic constructor
0qln opened this issue · comments
Issue Description
I have the class EventAccessor<T>
like following:
/// <summary>
/// Expose the `OnChanged` event of a property.
/// </summary>
/// <typeparam name="T"></typeparam>
internal class EventAccessor<T> : IImmutable
{
/// <summary>
/// This event will be invoked whenever the value of the property of this accessor changes.
/// </summary>
public event EventHandler? OnChanged
{
add
{
_property.OnChanged += value;
}
remove
{
_property.OnChanged -= value;
}
}
protected readonly Immutable<T> _property;
}
Adding the primary constructor
internal class EventAccessor<T>(Immutable<T> value) : IImmutable
{
/// <summary>
/// This event will be invoked whenever the value of the property of this accessor changes.
/// </summary>
public event EventHandler? OnChanged
{
add
{
_property.OnChanged += value;
}
remove
{
_property.OnChanged -= value;
}
}
protected readonly Immutable<T> _property = value;
}
and trying to run the project yields the error:
Error MSB6006 "csc.exe" exited with code -2146232797. compiler-bug C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets 84
I am not sure where to report this bug, as it seems to be related to the new C# version, but the error is a MSB
error, so I suppose I'm gonna start here.
Also: This bug is, atleast for me, not urgent; one can simple fallback to using the classic constructor (Although it was very annoying to track down the source of the error)
Steps to Reproduce
I have stripped my original project down to the minimal stuff needed for the error to occur:
- Create a new .NET 8 Console Application.
- Create the files with contents as in the example repository https://github.com/0qln/compiler-bug
- Try to run the application
Expected Behavior
Successful build
Actual Behavior
Throws the error:
Error MSB6006 "csc.exe" exited with code -2146232797. Application C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets 84
Analysis
I have no experience in debugging this close to the source, but if it helps, here is the code snipped that visual studio tells me is throwing the error:
<!-- Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler -->
<Csc Condition="'%(_CoreCompileResourceInputs.WithCulture)' != 'true'"
AdditionalLibPaths="$(AdditionalLibPaths)"
AddModules="@(AddModules)"
AdditionalFiles="@(AdditionalFiles)"
AllowUnsafeBlocks="$(AllowUnsafeBlocks)"
AnalyzerConfigFiles="@(EditorConfigFiles)"
Analyzers="@(Analyzer)"
ApplicationConfiguration="$(AppConfigForCompiler)"
BaseAddress="$(BaseAddress)"
CheckForOverflowUnderflow="$(CheckForOverflowUnderflow)"
ChecksumAlgorithm="$(ChecksumAlgorithm)"
CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)"
CodePage="$(CodePage)"
DebugType="$(DebugType)"
DefineConstants="$(DefineConstants)"
DelaySign="$(DelaySign)"
DisabledWarnings="$(NoWarn)"
DisableSdkPath="$(DisableSdkPath)"
DocumentationFile="@(DocFileItem)"
EmbedAllSources="$(EmbedAllSources)"
EmbeddedFiles="@(EmbeddedFiles)"
EmitDebugInformation="$(DebugSymbols)"
EnvironmentVariables="$(CscEnvironment)"
ErrorEndLocation="$(ErrorEndLocation)"
ErrorLog="$(ErrorLog)"
ErrorReport="$(ErrorReport)"
Features="$(Features)"
InterceptorsPreviewNamespaces="$(InterceptorsPreviewNamespaces)"
FileAlignment="$(FileAlignment)"
GeneratedFilesOutputPath="$(CompilerGeneratedFilesOutputPath)"
GenerateFullPaths="$(GenerateFullPaths)"
HighEntropyVA="$(HighEntropyVA)"
Instrument="$(Instrument)"
KeyContainer="$(KeyContainerName)"
KeyFile="$(KeyOriginatorFile)"
LangVersion="$(LangVersion)"
LinkResources="@(LinkResource)"
MainEntryPoint="$(StartupObject)"
ModuleAssemblyName="$(ModuleAssemblyName)"
NoConfig="true"
NoLogo="$(NoLogo)"
NoStandardLib="$(NoCompilerStandardLib)"
NoWin32Manifest="$(NoWin32Manifest)"
Nullable="$(Nullable)"
Optimize="$(Optimize)"
Deterministic="$(Deterministic)"
PublicSign="$(PublicSign)"
OutputAssembly="@(IntermediateAssembly)"
OutputRefAssembly="@(IntermediateRefAssembly)"
PdbFile="$(PdbFile)"
Platform="$(PlatformTarget)"
Prefer32Bit="$(Prefer32Bit)"
PreferredUILang="$(PreferredUILang)"
ProvideCommandLineArgs="$(ProvideCommandLineArgs)"
References="@(ReferencePathWithRefAssemblies)"
RefOnly="$(ProduceOnlyReferenceAssembly)"
ReportAnalyzer="$(ReportAnalyzer)"
ReportIVTs="$(ReportIVTs)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SharedCompilationId="$(SharedCompilationId)"
SkipAnalyzers="$(_SkipAnalyzers)"
SkipCompilerExecution="$(SkipCompilerExecution)"
Sources="@(Compile)"
SubsystemVersion="$(SubsystemVersion)"
TargetType="$(OutputType)"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)"
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)"
UseSharedCompilation="$(UseSharedCompilation)"
Utf8Output="$(Utf8Output)"
VsSessionGuid="$(VsSessionGuid)"
WarningLevel="$(WarningLevel)"
WarningsAsErrors="$(WarningsAsErrors)"
WarningsNotAsErrors="$(WarningsNotAsErrors)"
Win32Icon="$(ApplicationIcon)"
Win32Manifest="$(Win32Manifest)"
Win32Resource="$(Win32Resource)"
PathMap="$(PathMap)"
SourceLink="$(SourceLink)">
<Output TaskParameter="CommandLineArgs" ItemName="CscCommandLineArgs" />
</Csc>
in the file C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets
Versions & Configurations
msbuild -version
output:
MSBuild version 17.9.8+b34f75857 for .NET Framework
17.9.8.16306
I think it's a duplicate of dotnet/roslyn#71400
Yep, looks like it. Should we close this issue then?
Duplicate of dotnet/roslyn#71400