Skip to content

QueryVisualStudioInstances() fails with NullReferenceException when VSINSTALLDIR is set #65

@ap0llo

Description

@ap0llo

When the VSINSTALLDIR environment variable is set even though the tool is not running from a Developer command prompt, QueryVisualStudioInstances() fails with a NullReferenceException.

Stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Build.Locator.VisualStudioInstance..ctor(String name, String path, Version version, DiscoveryType discoveryType)
   at Microsoft.Build.Locator.MSBuildLocator.GetDevConsoleInstance()
   at Microsoft.Build.Locator.MSBuildLocator.<GetInstances>d__20.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)

Looking at the code, I guess there is a version != null check missing in GetDevConsoleInstance

This also happens when DiscoveryTypes is set to DiscoveryType.VisualStudioSetup only

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions