Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Oct 2, 2025

Backport of #12594 to vs18.0

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2586915/

Context

the recent change ac5fef4#diff-40f77147ccc6867c10324ec4ddf8110ede2e43499d939b73ef83c7f5febb7a75 doesn't have null check on an attempt to get property from _environmentVariableProperties collection that can be null.

Changes Made

Handle possible null ref exception.

More details

In the referenced ticket you can find a dump and check the callstack of exception and exact line that throws:

0:000> !ip2md 00007FFE726D8367
MethodDesc:   00007ffe71fca150
Method Name:  Microsoft.Build.Execution.ProjectInstance..ctor(Microsoft.Build.Execution.ProjectInstance, Boolean, Microsoft.Build.Execution.RequestedProjectState)
Class:        00007ffe7221bdc8
MethodTable:  00007ffe72018e50
mdToken:      00000000060015c7
Module:       00007ffe71fb1000
IsJitted:     yes
CodeAddr:     00007ffe726d79b0
Transparency: Critical
**Source file:  /_/src/Build/Instance/ProjectInstance.cs @ 848**

and the ProjectInstance with _environmentVariableProperties = null

0:000> !do 0000020eeb96b220
Name:        Microsoft.Build.Execution.ProjectInstance
MethodTable: 00007ffe72018e50
EEClass:     00007ffe7221bdc8
Size:        256(0x100) bytes
File:        C:\Program Files\Microsoft Visual Studio\18\Preview\MSBuild\Current\Bin\Microsoft.Build.dll
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
00007ffe720565b0  400079f        8 ...Microsoft.Build]]  0 instance 0000000000000000 _actualTargets
00007ffe720564e8  40007a0       10 ...Microsoft.Build]]  0 instance 0000000000000000 _targets
00007fff11f93348  40007a1       18 ...tring, mscorlib]]  0 instance 0000000000000000 _defaultTargets
00007fff11f93348  40007a2       20 ...tring, mscorlib]]  0 instance 0000000000000000 _initialTargets
00007fff11f88eb0  40007a3       28 ...tring, mscorlib]]  0 instance 0000000000000000 _importPaths
00007fff11f88eb0  40007a4       30 ...tring, mscorlib]]  0 instance 0000000000000000 _importPathsIncludingDuplicates
00007ffe7201de08  40007a5       38 ...Microsoft.Build]]  0 instance 0000020eeb96b320 _globalProperties
00007fff106d03a0  40007a6       40 ...tring, mscorlib]]  0 instance 0000000000000000 _globalPropertiesToTreatAsLocal
00007fff11f9c638  40007a7       f4       System.Boolean  1 instance                0 _explicitToolsVersionSpecified
00007ffe7201de08  40007a8       48 ...Microsoft.Build]]  0 instance 0000020eeb96bee0 _properties
00007ffe7201de08  40007a9       50 ...Microsoft.Build]]  **0 instance 0000000000000000 _environmentVariableProperties**
00007ffe7201de08  40007aa       58 ...Microsoft.Build]]  0 instance 0000000000000000 _sdkResolvedEnvironmentVariableProperties
00007ffe72079e88  40007ab       60 ...Microsoft.Build]]  0 instance 0000020eeb96c890 _items
00007ffe7207b3a8  40007ac       68 ...Microsoft.Build]]  0 instance 0000000000000000 _itemsByEvaluatedInclude
00007fff11fa07a0  40007ad       70        System.String  0 instance 0000000000000000 _directory
00007ffe72025028  40007ae       78 ...n.ElementLocation  0 instance 0000000000000000 _projectFileLocation
00007ffe720797f8  40007af       80 ...Microsoft.Build]]  0 instance 0000000000000000 _itemDefinitions
00007ffe7202af50  40007b0       88 ...tion.HostServices  0 instance 0000000000000000 _hostServices
00007fff11f9c638  40007b1       f5       System.Boolean  1 instance                0 _usingDifferentToolsVersionFromProjectFile
00007fff11fa07a0  40007b2       90        System.String  0 instance 0000000000000000 _originalProjectToolsVersion
00007fff11f9c638  40007b3       f6       System.Boolean  1 instance                1 _isImmutable
00007ffe7205ac40  40007b4       98 ...ild]], mscorlib]]  0 instance 0000000000000000 _beforeTargets
00007ffe7205ac40  40007b5       a0 ...ild]], mscorlib]]  0 instance 0000000000000000 _afterTargets
00007ffe72021a70  40007b6       a8 ...valuation.Toolset  0 instance 0000000000000000 _toolset
00007fff11fa07a0  40007b7       b0        System.String  0 instance 0000000000000000 _subToolsetVersion
00007ffe720307d0  40007b8       b8 ...tion.TaskRegistry  0 instance 0000000000000000 _taskRegistry
00007fff11f9c638  40007b9       f7       System.Boolean  1 instance                0 _translateEntireState
00007fff11fa3368  40007ba       f0         System.Int32  1 instance               -1 _evaluationId
00007ffe7202bc58  40007bb       c0 ...estedProjectState  0 instance 0000020eeb96c438 _requestedProjectStateFilter
00007ffe720568e0  40007bc       c8 ...Microsoft.Build]]  0 instance 0000000000000000 <EvaluatedItemElements>k__BackingField
00007fff11f88f10  40007bd       d0 ...tring, mscorlib]]  0 instance 0000000000000000 <ImportPaths>k__BackingField
00007fff11f88f10  40007be       d8 ...tring, mscorlib]]  0 instance 0000000000000000 <ImportPathsIncludingDuplicates>k__BackingField
00007ffe7201f388  40007bf       e0 ...tElementCacheBase  0 instance 0000000000000000 <ProjectRootElementCache>k__BackingField
00007ffe72030320  40007c0       e8 ...ng.LoggingContext  0 instance 0000000000000000 _loggingContext

Testing

Manual

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants