-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (54 loc) · 1.88 KB
/
Program.cs
File metadata and controls
60 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Threading.Tasks;
using Windows.Devices.Enumeration.Pnp;
using System.Linq;
using WinRT;
namespace IncorrectValueRepro
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
TestProperties().Wait(10000);
}
private static async Task TestProperties()
{
// All these properties are not used directly in the repro code but are necessary to produce the
// issue as they create recyclable ptrs and get disposed
var requestedDeviceProperties =
new System.Collections.Generic.List<string>()
{
"System.Devices.ClassGuid",
"System.Devices.ContainerId",
"System.Devices.DeviceHasProblem",
"System.Devices.DeviceInstanceId",
"System.Devices.Parent",
"System.Devices.Present",
"System.ItemNameDisplay",
"System.Devices.Children",
};
var devicefilter = "System.Devices.Present:System.StructuredQueryType.Boolean#True";
var presentDevices = (await PnpObject.FindAllAsync(PnpObjectType.Device, requestedDeviceProperties, devicefilter).AsTask().ConfigureAwait(false)).Select(pnpObject => {
var prop = pnpObject.Properties;
foreach (var key in pnpObject.Properties.Keys)
{
var val = prop[key];
if (val == null) continue;
if (key == "System.Devices.ContainerId" && val is not Guid)
{
// This is where the value of IntPtr of val is same as a recycled IntPtr
// The new type and value is thus incorrect
throw new Exception("Unexpected type");
}
if ((key == "System.Devices.Parent" || key == "System.Devices.DeviceInstanceId" || key == "System.ItemNameDisplay") && val is not string)
{
// Same case as above
throw new Exception("Unexpected type");
}
}
return pnpObject;
}).ToList();
}
}
}