Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

[Core] Fix null reference when opening SDK style project #5046

Merged
merged 2 commits into from Jun 12, 2018

Conversation

mrward
Copy link
Member

@mrward mrward commented Jun 12, 2018

On opening a SDK style project sometimes a null reference exception
was logged.

System.NullReferenceException: Object reference not set to an instance
of an object
  at MonoDevelop.Projects.MSBuild.DefaultMSBuildEngine+<FindGlobItemsIncludingFile>d__85.MoveNext ()
  in MonoDevelop.Projects.MSBuild/DefaultMSBuildEngine.cs:1441
  at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext ()
  in System/Linq/Where.cs:140
  at MonoDevelop.Projects.Project.OnFileCreatedExternally (System.String fileName)
  in MonoDevelop.Projects/Project.cs:4293
  at MonoDevelop.Projects.Project+<>c__DisplayClass338_0.<OnFileCreated>b__0 ()
  in MonoDevelop.Projects/Project.cs:4258

This was difficult to reproduce. In the end adding a Thread.Sleep in
MSBuildProjectInstance's Dispose and Evaluate methods between where
the engine is set and the projectInstance is set was a way to make it
happen more consistently. So the problem seems to be that if a file
is generated externally when the engine is not null but the
projectInstance is null then a null reference exception would occur.
Now the projectInstance being null is handled. The file being
generated on project load was a .tmp file that would not be added
to the project.

Fixes VSTS #611795 - NRE when file externally added

On opening a SDK style project sometimes a null reference exception
was logged.

System.NullReferenceException: Object reference not set to an instance
of an object
  at MonoDevelop.Projects.MSBuild.DefaultMSBuildEngine+<FindGlobItemsIncludingFile>d__85.MoveNext ()
  in MonoDevelop.Projects.MSBuild/DefaultMSBuildEngine.cs:1441
  at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext ()
  in System/Linq/Where.cs:140
  at MonoDevelop.Projects.Project.OnFileCreatedExternally (System.String fileName)
  in MonoDevelop.Projects/Project.cs:4293
  at MonoDevelop.Projects.Project+<>c__DisplayClass338_0.<OnFileCreated>b__0 ()
  in MonoDevelop.Projects/Project.cs:4258

This was difficult to reproduce. In the end adding a Thread.Sleep in
MSBuildProjectInstance's Dispose and Evaluate methods between where
the engine is set and the projectInstance is set was a way to make it
happen more consistently. So the problem seems to be that if a file
is generated externally when the engine is not null but the
projectInstance is null then a null reference exception would occur.
Now the projectInstance being null is handled. The file being
generated on project load was a .tmp file that would not be added
to the project.

Fixes VSTS #611795 - NRE when file externally added
Add the same engine and projectInstance checks to the
FindUpdateGlobItemsIncludingFile method so it is consistent with the
FindGlobItemsIncludingFile method.
@mrward mrward requested a review from slluis as a code owner June 12, 2018 15:27
@mrward
Copy link
Member Author

mrward commented Jun 12, 2018

@monojenkins backport release-7.6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants