dotnet / api-docs-sync

Tools for porting documentation from intellisense xmls to api-docs, or from api-docs to triple slash comments.
MIT License
10 stars 16 forks source link

Tool fails to run with System.InvalidOperationException: #38

Open ericstj opened 3 years ago

ericstj commented 3 years ago

I tried to run the tool on a dotnet/runtime library and hit the following error:

Specified Docs xml locations:
  -  c:\src\dotnet\dotnet-api-docs\xml
Included assemblies:
 - System.IO.Pipelines
Included namespaces:
 - System.IO
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Libraries.ToTripleSlashPorter.LoadVSInstance() in C:\src\carlossanlop\DocsPortingTool\Libraries\ToTripleSlashPorter.cs:line 439
   at Libraries.ToTripleSlashPorter.Start(Configuration config) in C:\src\carlossanlop\DocsPortingTool\Libraries\ToTripleSlashPorter.cs:line 112
   at DocsPortingTool.DocsPortingTool.Main(String[] args) in C:\src\carlossanlop\DocsPortingTool\Program\DocsPortingTool.cs:line 22

@carlossanlop

ericstj commented 3 years ago

So I tried to run the tool from the IDE to debug it (rather than the tool install) and this didn't repro, so the problem might be with the tool packaging.

ericstj commented 3 years ago

Something about this is machine state dependent. After trying to repro a few times and poking around in debugger it no longer reproed even from the commandline.

ericstj commented 3 years ago

Got a repro. This is the error when the SDK listed in global.json doesn't exist on the machine. Oddly enough the global.json used by the tool appears to be based on working directory the tool was launched from, not the directory of the project.

To repro you can create a global.json with a non-existent SDK version and put that in the working directory or up the tree.

Suggestion: Set WorkingDirectory of the VS query to the project directory. If you still get an error finding instances, raise the error telling user to make sure project was buildable rather than throwing IOE.

carlossanlop commented 3 years ago

Thanks for sharing, @ericstj

This is the error when the SDK listed in global.json doesn't exist on the machine.

So if I am interpreting your description correctly, if the tool targets net5.0, but my machine does not have net5.0 it installed, I will repro this issue?

ericstj commented 3 years ago

It doesn't have much to do with the tool's target.

Simply do the following:

  1. Create a global.json like the following (using a fake version):

{ "sdk": { "version": "6.0.100-preview.42", "allowPrerelease": true } }


2. Put that global.json in a directory. 
3. CD to that directory.
4. Run the tool on some project anywhere else.

Expect: tool can load and process a project regardless of where it's executed from.
Actual: tool fails with IOE due to using the global.json from it's own working directory.
safern commented 3 years ago

I see... so it seems like the call to LoadVSInstance might be getting the global.json of the tool cwd. We need to investigate if there is a way to tell the resolvers to use the project cwd.

safern commented 3 years ago

Ah I see @ericstj already found out how to do that:

Set WorkingDirectory of the VS query to the project directory. If you still get an error finding instances, raise the error telling user to make sure project was buildable rather than throwing IOE.