Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Build fails for primary contructor, but not classic constructor #10077

Closed
0qln opened this issue Apr 25, 2024 · 3 comments
Closed

[Bug]: Build fails for primary contructor, but not classic constructor #10077

0qln opened this issue Apr 25, 2024 · 3 comments
Labels

Comments

@0qln
Copy link

0qln commented Apr 25, 2024

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:

  1. Create a new .NET 8 Console Application.
  2. Create the files with contents as in the example repository https://github.com/0qln/compiler-bug
  3. 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
@0qln 0qln added the bug label Apr 25, 2024
@0qln 0qln changed the title [Bug]: Build failes for primary contructor, but not classic constructor [Bug]: Build fails for primary contructor, but not classic constructor Apr 25, 2024
@KalleOlaviNiemitalo
Copy link

I think it's a duplicate of dotnet/roslyn#71400

@0qln
Copy link
Author

0qln commented Apr 25, 2024

Yep, looks like it. Should we close this issue then?

@rainersigwald
Copy link
Member

Duplicate of dotnet/roslyn#71400

@rainersigwald rainersigwald marked this as a duplicate of dotnet/roslyn#71400 Apr 25, 2024
@rainersigwald rainersigwald closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants