Q:

QueryDisplayConfig() does not initialize pathArray and modeArray correctly

I'm trying to set-up an easy 1-click change of the mode of my screens (extended <--> disconnected)
but my screens are assigned no ID by the QueryDisplayConfig method.
(I'm using the User32 PInvoke lib from https://github.com/AArnott/pinvoke, in addition to what you can find in the code below)
I tried:

stepping through the code with breakpoints, making sure EVERY value is the default value.
elevating VS to run with administrator privileges.  
making extra sure that the flags and errors are functioning correctly. 

[DllImport("User32.dll")]
public static extern int GetDisplayConfigBufferSizes(uint flags, ref uint numPathArrayElements, ref uint numModeInfoArrayElements);
[DllImport("User32.dll")]
public static extern int QueryDisplayConfig(
    uint flags,
    ref uint numPathArrayElements, DISPLAYCONFIG_PATH_INFO[] pathArray,
    ref uint numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO[] modeInfoArray,
    DISPLAYCONFIG_TOPOLOGY_ID[] currentTopologyId
);

const int QDC_ALL_PATHS = 1;
const int QDC_ONLY_ACTIVE_PATHS = 2;
const int QDC_DATABASE_CURRENT = 4;

public static void CheckDisplays() {
    uint numPathArrayElements = 0;
    uint numModeInfoArrayElements = 0;
    uint filter = QDC_ONLY_ACTIVE_PATHS;

    int bufferError = GetDisplayConfigBufferSizes(filter, ref numPathArrayElements, ref numModeInfoArrayElements);

    DISPLAYCONFIG_PATH_INFO[] pathArray = new DISPLAYCONFIG_PATH_INFO[numPathArrayElements];
    DISPLAYCONFIG_MODE_INFO[] modeArray = new DISPLAYCONFIG_MODE_INFO[numModeInfoArrayElements];

    int queryError = QueryDisplayConfig(filter, ref numPathArrayElements, pathArray, ref numModeInfoArrayElements, modeArray, null);

    Console.WriteLine();
    Console.WriteLine("Elements: " + numPathArrayElements); // Prints the correct amount of connected screens.
    Console.WriteLine("BUFFER ERROR: " + bufferError);      // Prints 0 -- as in Success.
    Console.WriteLine("PATH ERROR: " + queryError);         // Prints 0 -- as in Success.

    for (int i = 0; i < pathArray.Length; i++) {
        if (pathArray[i].sourceInfo.id != 0) { Console.WriteLine($"Path{i} has been initialized correctly!!"); }
        // Every object in the array has default values and IDs of 0.
        // Nothing prints here.
    }
}

Each screen should be assigned an ID and a proper mode. 
Instead, everything has the default value and I seem to be stuck.

A:

Your declaration for QueryDisplayConfig is wrong : arrays must be [Out]
This works for me :
(I have only 1 monitor but the values received in arrays are the same as in C++ (I translated structures from SDK headers))
(IntPtr.Zero for currentTopologyId with QDC_ONLY_ACTIVE_PATHS)
    [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    public static extern int QueryDisplayConfig(uint flags, ref uint numPathArrayElements, [Out] DISPLAYCONFIG_PATH_INFO[] pathArray,
        ref uint modeInfoArrayElements, [Out] DISPLAYCONFIG_MODE_INFO[] modeInfoArray, IntPtr currentTopologyId);

