Skip to content

fix exception with null sdk version - #2058

Open
corngood wants to merge 1 commit into
OmniSharp:masterfrom
corngood:null-version-fix
Open

fix exception with null sdk version#2058
corngood wants to merge 1 commit into
OmniSharp:masterfrom
corngood:null-version-fix

Conversation

@corngood

Copy link
Copy Markdown
Contributor

I've been getting errors like:

{"Event":"log","Body":{"LogLevel":"ERROR","Name":"OmniSharp.MSBuild.ProjectLoadListener","Message":"Unexpected exception got thrown from project load listener: System.NullReferenceException: Object reference not set to an instance of an object\n at OmniSharp.MSBuild.ProjectLoadListener.GetSdkVersion (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0000b] in <7e6cb753aca94549b693616e0e7d1016>:0 \n at OmniSharp.MSBuild.ProjectLoadListener.ProjectLoaded (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0001a] in <7e6cb753aca94549b693616e0e7d1016>:0 "},"Seq":137,"Type":"event"}

This happens when dotnet isn't available in PATH. Omnisharp runs dotnet --info and if it fails, SdkVersion ends up null.

My change is a bit hacky. Perhaps it would be better to propagate the null through to ProjectConfigurationMessage.SdkVersion? That seems to be the only place it's used, but it might be a breaking protocol change.

This happens when the dotnet sdk isn't available in PATH.
@dnfadmin

dnfadmin commented Dec 31, 2020

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

private static HashedString GetSdkVersion(ProjectLoadedEventArgs args)
{
return _tfmAndFileHashingAlgorithm.HashInput(args.SdkVersion.ToString());
return _tfmAndFileHashingAlgorithm.HashInput($"{args.SdkVersion}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just return a null I think
however, a better question is if we should allow to start without dotnet on the path at all.
There would be other things that will fail without it e.g. auto restore or test adapter

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants