rubicon-oss / LicenseHeaderManager

Manage license headers for your source code files in Visual Studio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Error message appears when visual studio reloads a project in a solution folder

lachlan-trmb opened this issue · comments

If I have a solution with a structure like this (in the Visual Studio solution explorer):

MySolution
  |--->Project1
  |--->SolutionFolder (a system folder is not required here)
         |--->Project2

Whenever visual studio reloads Project2 a message box is show with the error message "Asynchronous Task failed: Object reference not set to an instance of an object". The message in the console is:

2021-10-25 14:50:49,339 [ERROR] LicenseHeaderManager.Utils.Extensions: Could not determine if project item  is open. Assuming it is closed.
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at EnvDTE.ProjectItem.get_IsOpen(String ViewKind)
   at LicenseHeaderManager.Utils.Extensions.IsOpen(ProjectItem item) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Utils\Extensions.cs:line 212
2021-10-25 14:50:50,510 [ERROR] LicenseHeaderManager.Utils.Extensions: Asynchronous Task failed
System.NullReferenceException: Object reference not set to an instance of an object.
   at LicenseHeaderManager.Core.LicenseHeaderReplacer.<>c__DisplayClass9_0.<GetLanguageFromExtension>b__1(String y)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at LicenseHeaderManager.Core.LicenseHeaderReplacer.<>c__DisplayClass9_0.<GetLanguageFromExtension>b__0(Language x)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at LicenseHeaderManager.Core.LicenseHeaderReplacer.GetLanguageFromExtension(String extension)
   at LicenseHeaderManager.Utils.CoreHelpers.TryOpenDocument(ProjectItem item, ILicenseHeaderExtension extension) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Utils\CoreHelpers.cs:line 297
   at LicenseHeaderManager.Utils.Extensions.GetContent(ProjectItem item, Boolean& wasAlreadyOpen, ILicenseHeaderExtension extension) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Utils\Extensions.cs:line 172
   at LicenseHeaderManager.LicenseHeadersPackage.<FinishedAddingItemAsync>d__63.MoveNext() in C:\Build\1776828f99d31c99\LicenseHeaderManager\LicenseHeadersPackage.cs:line 406
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LicenseHeaderManager.Utils.Extensions.<<FireAndForget>g__ForgetAwaited|9_0>d.MoveNext() in C:\Build\1776828f99d31c99\LicenseHeaderManager\Utils\Extensions.cs:line 272

The message box and console errors occur twice each time.

@lachlan-trmb I have the same structure, edited a project file via text editor to get it to reload (requires a file with the classic project format), but was not able to reproduce the error.

@MichaelKetting That's unexpected. I've just retried it and discovered some additional detail. My full steps are:

  1. Open VS2019
  2. Create a new project (which will therefore create a new solution)
  3. Close the solution
  4. Reopen the solution
  5. Add a solution folder to the solution
  6. Add another project in the solution folder - at this point the error message appears once.
  7. Edit the csproj of the project created in step 6. in a text editor - remove a reference to a code file and save the csproj
  8. Go back to visual studio - allow it to reload the project when prompted
  9. The error message now appears twice.

Note that steps 3 & 4 appear to be important - i.e. the issue only occurs when you have opened an existing solution. I just discovered this detail now. Also in step 6 & 7 it is important that the project being edited is one inside a solution folder.

Here is a short video going through the full steps: https://user-images.githubusercontent.com/93138628/141966000-a00b90ae-12e7-49b9-a043-86ae03cb49a4.mp4

Thanks for the good repro. I couldn't retry it with your steps right now, but it seems to be a very particular scenario, so great find! Is this something that's blocking you or just an edge case in your work?

I wouldn't say it is blocking me because although it happens regularly for my team it is just an annoyance because of having to close the error dialogs