dotnet / dotnet/project-system

ProjectReference to a Project with TargetType=module crashes VS

Open
#5,380 6 comments 0 reactions 1 assignee Assigned to @davkean View on GitHub
Feature-Language-Service Triage-Approved
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

- 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.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.d__32.MoveNext() in /_/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 707"
```

This is what I'm seeing in `CompilationReference.cs`:

```C#
internal static MetadataReferenceProperties GetProperties(Compilation compilation, ImmutableArray 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](https://github.com/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](https://github.com/dotnet/project-system/files/3544533/module-crash-repro.zip)

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.