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

csc.exe exited with code -2146232797 when using primary constructor with event in interface #72981

Closed
ds1709 opened this issue Apr 11, 2024 · 2 comments
Labels
Area-Compilers Bug New Feature - Primary Constructors untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@ds1709
Copy link

ds1709 commented Apr 11, 2024

Version Used:
VS 17.9.2

Steps to Reproduce:
Just define next types:

    public sealed class Foo(DbConnection connection) : IFoo
    {
        public event EventHandler Bar
        {
            add => connection.Disposed += value;
            remove => connection.Disposed -= value;
        }
    }

    public interface IFoo
    {
        event EventHandler Bar;
    }

The key point is:

  • use primary constructor;
  • class must implement interface;
  • interface must contain event;
  • event must be implemented via primary constructor parameter.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 11, 2024
@svick
Copy link
Contributor

svick commented Apr 11, 2024

When I put this code into SharpLab, I get the following exception:

System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol.get_ParameterCount()
   at Microsoft.CodeAnalysis.CSharp.InMethodBinder.LookupSymbolsInSingleBinder(LookupResult result, String name, Int32 arity, ConsList`1 basesBeingResolved, LookupOptions options, Binder originalBinder, Boolean diagnose, CompoundUseSiteInfo`1& useSiteInfo)
   at Microsoft.CodeAnalysis.CSharp.Binder.LookupSymbolsInternal(LookupResult result, String name, Int32 arity, ConsList`1 basesBeingResolved, LookupOptions options, Boolean diagnose, CompoundUseSiteInfo`1& useSiteInfo)
   at Microsoft.CodeAnalysis.CSharp.Binder.IdentifierUsedAsValueFinder.CheckIdentifiersInNode(CSharpSyntaxNode node, Binder binder)
   at Microsoft.CodeAnalysis.CSharp.Binder.CapturedParametersFinder.<GetCapturedParameters>g__checkParameterReferencesInMethodBody|4_2(CSharpSyntaxNode syntaxNode, Binder bodyBinder, <>c__DisplayClass4_0&)
   at Microsoft.CodeAnalysis.CSharp.Binder.CapturedParametersFinder.GetCapturedParameters(SynthesizedPrimaryConstructor primaryConstructor)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedPrimaryConstructor.GetBackingFields()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.AddSynthesizedTypeMembersIfNecessary(MembersAndInitializersBuilder builder, DeclaredMembersAndInitializers declaredMembersAndInitializers, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.BuildMembersAndInitializers(BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersByNameSlow()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersByName()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersUnordered()
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.MakeExplicitInterfaceImplementationMap()
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.GetExplicitImplementationForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationForInterfaceMember(Symbol interfaceMember, TypeSymbol implementingType, BindingDiagnosticBag diagnostics, Boolean ignoreImplementationInInterfaces, Boolean& implementationInInterfacesMightChangeResult)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMemberInNonInterfaceWithDiagnostics(Symbol interfaceMember, Boolean ignoreImplementationInInterfacesIfResultIsNotReady)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceEventSymbol.ComputeIsWindowsRuntimeEvent()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceEventAccessorSymbol.MethodChecks(BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberMethodSymbol.LazyMethodChecks()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceEventAccessorSymbol.get_Parameters()
   at Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol.get_ParameterCount()
   at Microsoft.CodeAnalysis.CSharp.InMethodBinder.LookupSymbolsInSingleBinder(LookupResult result, String name, Int32 arity, ConsList`1 basesBeingResolved, LookupOptions options, Binder originalBinder, Boolean diagnose, CompoundUseSiteInfo`1& useSiteInfo)
   at Microsoft.CodeAnalysis.CSharp.Binder.LookupSymbolsInternal(LookupResult result, String name, Int32 arity, ConsList`1 basesBeingResolved, LookupOptions options, Boolean diagnose, CompoundUseSiteInfo`1& useSiteInfo)
   at Microsoft.CodeAnalysis.CSharp.Binder.IdentifierUsedAsValueFinder.CheckIdentifiersInNode(CSharpSyntaxNode node, Binder binder)
   at Microsoft.CodeAnalysis.CSharp.Binder.CapturedParametersFinder.<GetCapturedParameters>g__checkParameterReferencesInMethodBody|4_2(CSharpSyntaxNode syntaxNode, Binder bodyBinder, <>c__DisplayClass4_0&)
   at Microsoft.CodeAnalysis.CSharp.Binder.CapturedParametersFinder.GetCapturedParameters(SynthesizedPrimaryConstructor primaryConstructor)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedPrimaryConstructor.GetBackingFields()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.AddSynthesizedTypeMembersIfNecessary(MembersAndInitializersBuilder builder, DeclaredMembersAndInitializers declaredMembersAndInitializers, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.BuildMembersAndInitializers(BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersByNameSlow()
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Symbol.ForceCompleteMemberByLocation(SourceLocation locationOpt, Symbol member, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamespaceSymbol.<>c__DisplayClass66_1.<ForceComplete>b__0(Int32 i)
   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass6_0`1.<WithCurrentUICulture>b__0(T param)
   at Roslyn.Utilities.RoslynParallel.<>c__DisplayClass1_0.<For>g__errorHandlingBody|0(Int32 i)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
   at Roslyn.Utilities.RoslynParallel.For(Int32 fromInclusive, Int32 toExclusive, Action`1 body, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamespaceSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceModuleSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Symbols.SourceAssemblySymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSourceDeclarationDiagnostics(SyntaxTree syntaxTree, Nullable`1 filterSpanWithinTree, Func`4 locationFilterOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsWithoutFiltering(CompilationStage stage, Boolean includeEarlierStages, BindingDiagnosticBag builder, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<GetAllDiagnosticsAsync>g__getAllDiagnosticsWithoutStateTrackingAsync|35_0(ImmutableArray`1 analyzers, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAllDiagnosticsAsync(CancellationToken cancellationToken)
   at MirrorSharp.Internal.Roslyn.RoslynSession.GetDiagnosticsAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Roslyn\RoslynSession.cs:line 99
   at MirrorSharp.Internal.Handlers.SlowUpdateHandler.ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Handlers\SlowUpdateHandler.cs:line 27
   at MirrorSharp.Internal.Connection.ReceiveAndProcessInternalAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Connection.cs:line 96
   at MirrorSharp.Internal.Connection.ReceiveAndProcessAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Connection.cs:line 54

@jjonescz
Copy link
Contributor

Looks like a duplicate of #71400, should be fixed since Visual Studio 17.10 Preview 1.

@jjonescz jjonescz closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug New Feature - Primary Constructors untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants