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

Unresolved reference in SolutionExplorer #29122

Closed
eugenr79 opened this Issue Aug 7, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@eugenr79
Copy link

eugenr79 commented Aug 7, 2018

Desc:

I use SolutionExplorer from Samples (https://github.com/dotnet/roslyn-sdk/tree/dev15.8.x)
It displays the project references as unresolved and calling the Project.GetCompilationAsync method fails with the ArgumentException: Reference of type 'Microsoft.CodeAnalysis.UnresolvedMetadataReference' is not valid for this compilation.

Steps to Reproduce:

  1. Run SolutionExprorer from Roslyn SDK (https://github.com/dotnet/roslyn-sdk/tree/dev15.8.x)
  2. Open the attached project.
    TestVB2.zip
  3. Check references for ClassLibrary2. The reference on ClassLibrary1 will be unresolved.
  4. Try call the GetCompilationAsync for the ClassLibrary2 project.

For #4 you can simply add the following code into the ProjectViewModel constructor in SolutionExplorer project.

var task = project.GetCompilationAsync();
task.Wait(default(CancellationToken));
var compilation = task.Result;

Actual Behavior:
image

Expected Behavior:
VS solved this scenario well:
image

Actually I can live with the unresolved reference but I can not find the a way to skip the exceptions when some references get unresolved.

Here are the exception details:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(CancellationToken cancellationToken)
   at MSBuildWorkspaceTester.ViewModels.TaskExt.WaitForResult[T](Task`1 task, CancellationToken cancellationToken) in C:\My\Temp\roslyn-sdk-dev15.8.x\samples\CSharp\SolutionExplorer\ViewModels\ProjectViewModel.cs:line 15
   at MSBuildWorkspaceTester.ViewModels.ProjectViewModel..ctor(Workspace workspace, ProjectId projectId) in C:\My\Temp\roslyn-sdk-dev15.8.x\samples\CSharp\SolutionExplorer\ViewModels\ProjectViewModel.cs:line 39
   at MSBuildWorkspaceTester.ViewModels.SolutionViewModel..ctor(Workspace workspace) in C:\My\Temp\roslyn-sdk-dev15.8.x\samples\CSharp\SolutionExplorer\ViewModels\SolutionViewModel.cs:line 14
   at MSBuildWorkspaceTester.ViewModels.MainWindowViewModel.<OpenProjectExecuted>d__17.MoveNext() in C:\My\Temp\roslyn-sdk-dev15.8.x\samples\CSharp\SolutionExplorer\ViewModels\MainWindowViewModel.cs:line 94
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at MSBuildWorkspaceTester.App.Main()
Inner Exception 1:
ArgumentException: Reference of type 'Microsoft.CodeAnalysis.UnresolvedMetadataReference' is not valid for this compilation.
Parameter name: references[1]
@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Oct 3, 2018

I'll take a look. MSBuildWorkspace is supposed to lift any unresolved metadata references to project references.

@DustinCampbell DustinCampbell self-assigned this Oct 4, 2018

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Oct 4, 2018

I can reproduce the issue using the provided test project (thanks!) and the Solution Explorer sample.

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Oct 4, 2018

I think I see the issue. The problem is that the <OutputPath/> property in both ClassLibrary1.vbproj and ClassLibrary2.vbproj is only set when the Platform is x86. However, the project sets Platform to AnyCPU if hasn't already been set elsewhere, so MSBuildWorkspace is assuming AnyCPU. I can see a similar issue in Visual Studio if I first delete the .vs folder from the root of your repro sample.

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Oct 4, 2018

Unfortunately, MSBuildWorkspace doesn't know how to handle the highly-undocumented information in the file TestVB2.suo in the .vs folder, which is where the previously selected Configuration and Platform are stored.

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Oct 4, 2018

I have a fix for this that introduces a fallback when a project reference cannot be resolved to a metadata reference because a project's information is incomplete.

DustinCampbell added a commit to DustinCampbell/roslyn that referenced this issue Oct 9, 2018

DustinCampbell added a commit to DustinCampbell/roslyn that referenced this issue Oct 13, 2018

DustinCampbell added a commit to DustinCampbell/roslyn that referenced this issue Oct 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment