File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ private static string GetCachedDeviceId()
38
38
39
39
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
40
40
{
41
- // Get device Id from Windows registry
42
- using ( var key = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Microsoft\DeveloperTools" ) )
41
+ // Get device Id from Windows registry matching the OS architecture
42
+ using ( var key = RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Registry64 ) . OpenSubKey ( @"SOFTWARE\Microsoft\DeveloperTools" ) )
43
43
{
44
44
deviceId = key ? . GetValue ( "deviceid" ) as string ;
45
45
}
@@ -80,10 +80,16 @@ private static void CacheDeviceId(string deviceId)
80
80
{
81
81
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
82
82
{
83
- // Cache device Id in Windows registry
84
- using ( var key = Registry . CurrentUser . CreateSubKey ( @"SOFTWARE\Microsoft\DeveloperTools" ) )
83
+ // Cache device Id in Windows registry matching the OS architecture
84
+ using ( RegistryKey baseKey = RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Registry64 ) )
85
85
{
86
- key . SetValue ( "deviceid" , deviceId ) ;
86
+ using ( var key = baseKey . CreateSubKey ( @"SOFTWARE\Microsoft\DeveloperTools" ) )
87
+ {
88
+ if ( key != null )
89
+ {
90
+ key . SetValue ( "deviceid" , deviceId ) ;
91
+ }
92
+ }
87
93
}
88
94
}
89
95
else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
Original file line number Diff line number Diff line change @@ -50,12 +50,16 @@ public void TelemetryCommonPropertiesShouldReturnNewGuidWhenCannotGetMacAddress(
50
50
}
51
51
52
52
[ Fact ]
53
- public void TelemetryCommonPropertiesShouldReturnNewGuidWhenCannotDevDeviceId ( )
53
+ public void TelemetryCommonPropertiesShouldEnsureDevDeviceIDIsCached ( )
54
54
{
55
55
var unitUnderTest = new TelemetryCommonProperties ( userLevelCacheWriter : new NothingCache ( ) ) ;
56
56
var assignedMachineId = unitUnderTest . GetTelemetryCommonProperties ( ) [ "devdeviceid" ] ;
57
57
58
58
Guid . TryParse ( assignedMachineId , out var _ ) . Should ( ) . BeTrue ( "it should be a guid" ) ;
59
+ var secondAssignedMachineId = unitUnderTest . GetTelemetryCommonProperties ( ) [ "devdeviceid" ] ;
60
+
61
+ Guid . TryParse ( secondAssignedMachineId , out var _ ) . Should ( ) . BeTrue ( "it should be a guid" ) ;
62
+ secondAssignedMachineId . Should ( ) . Be ( assignedMachineId , "it should match the previously assigned guid" ) ;
59
63
}
60
64
61
65
[ Fact ]
You can’t perform that action at this time.
0 commit comments