question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ProjectReference to a Project with TargetType=module crashes VS

See original GitHub issue
  • Create a Project with TargetType=module
  • ProjectReference it from another project
  • Open the projects from VS.

Observed: VS will crash.

$exception
{"Can't create a reference to a module."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233067
    HelpLink: null
    IPForWatsonBuckets: 0x2a586a41
    InnerException: null
    IsTransient: false
    Message: "Can't create a reference to a module."
    RemoteStackTrace: null
    Source: "Microsoft.CodeAnalysis"
    StackTrace: "   at Microsoft.CodeAnalysis.CompilationReference.GetProperties(Compilation compilation, ImmutableArray`1 aliases, Boolean embedInteropTypes)\r\n   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.ToMetadataReference(ImmutableArray`1 aliases, Boolean embedInteropTypes)\r\n   at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetMetadataReferenceAsync>d__32.MoveNext() in /_/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 707"
    TargetSite: {Microsoft.CodeAnalysis.MetadataReferenceProperties GetProperties(Microsoft.CodeAnalysis.Compilation, System.Collections.Immutable.ImmutableArray`1[System.String], Boolean)}
    WatsonBuckets: null
    _HResult: -2146233067
    _className: "System.NotSupportedException"
    _data: {System.Collections.ListDictionaryInternal}
    _dynamicMethods: null
    _exceptionMethod: null
    _exceptionMethodString: null
    _helpURL: null
    _innerException: null
    _ipForWatsonBuckets: 0x2a586a41
    _message: "Can't create a reference to a module."
    _remoteStackIndex: 0
    _remoteStackTraceString: null
    _safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager}
    _source: null
    _stackTrace: {sbyte[96]}
    _stackTraceString: null
    _watsonBuckets: null
    _xcode: -532462766
    _xptrs: 0x00000000
"System.NotSupportedException: Can't create a reference to a module
at Microsoft.CodeAnalysis.CompilationReference.GetProperties(Compilation compilation, ImmutableArray`1 aliases, Boolean embedInteropTypes)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.ToMetadataReference(ImmutableArray`1 aliases, Boolean embedInteropTypes)
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetMetadataReferenceAsync>d__32.MoveNext() in /_/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 707"

This is what I’m seeing in CompilationReference.cs:

        internal static MetadataReferenceProperties GetProperties(Compilation compilation, ImmutableArray<string> aliases, bool embedInteropTypes)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }

            if (compilation.IsSubmission)
            {
                throw new NotSupportedException(CodeAnalysisResources.CannotCreateReferenceToSubmission);
            }

            if (compilation.Options.OutputKind == OutputKind.NetModule)
            {
                throw new NotSupportedException(CodeAnalysisResources.CannotCreateReferenceToModule);
            }

            return new MetadataReferenceProperties(MetadataImageKind.Assembly, aliases, embedInteropTypes);
        }

dotnet/wpf repo is planning on using netmodules it as part of product-binaries, and this would imply that the solution in the repo can not be used/built in VS. It would be great if netmodule-references can be supported in Dev16.4.

module-crash-repro.zip

/cc @rladuca /cc @tgani-msft, @dotnet/wpf-developers

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
davkeancommented, Aug 30, 2019

Note that reference is marked as:

    <ProjectReference Include="..\module\module.csproj">
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
       <OutputItemType>AddModules</OutputItemType>
    </ProjectReference>

Which should mean that it isn’t passed as reference, so we have a couple of bugs:

  1. We shouldn’t crash if someone doesn’t specify ReferenceOutputAssembly
  2. We shouldn’t be passing this module to Roslyn when ReferenceOutputAssembly is specified.

Probably a combination of Roslyn, Project and MSBuild bugs.

2reactions
davkeancommented, Aug 28, 2019

What’s the expectation here? Clearly we should do better than a crash - but a reference to a module isn’t valid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vs 2017 crashes when adding reference to project
VS 2017 often crashes when adding a reference to a project. Steps to produce: 1. open project references node.
Read more >
Visual Studio crashes on 'add reference'
Visual Studio crashes when opening any solution and right-clicking 'references' and choosing 'add reference'. The dialog opens for a few seconds ...
Read more >
Manage references in a project - Visual Studio (Windows)
Learn how to manage references to external components and connected services in a project.
Read more >
What is Project to Project reference & why is it needed
Understand C# project to project reference, and the benefits.
Read more >
Project References - TypeScript: Documentation
Project references are a new feature in TypeScript 3.0 that allow you to structure your TypeScript programs into smaller pieces.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found