{"record":{"id":"73a3b0f190f7660f","repo":"NickeManarin/ScreenToGif","slug":"looks-like-that-the-desktop-duplication-api-is-not","errorCode":null,"errorMessage":"Looks like that the Desktop Duplication API is not supported on this screen.","messagePattern":"Looks like that the Desktop Duplication API is not supported on this screen\\.","errorType":"exception","errorClass":"GraphicsConfigurationException","httpStatus":null,"severity":"error","filePath":"ScreenToGif/Capture/DirectImageCapture.cs","lineNumber":202,"sourceCode":"                {\n                    //Make sure to run with the integrated graphics adapter if using a Microsoft hybrid system. https://stackoverflow.com/a/54196789/1735672\n                    DuplicatedOutput = output1.DuplicateOutput(Device);\n                }\n                catch (SharpDXException e) when (e.Descriptor == SharpDX.DXGI.ResultCode.NotCurrentlyAvailable)\n                {\n                    throw new Exception(\"Too many applications using the Desktop Duplication API. Please close one of the applications and try again.\", e);\n                }\n                catch (SharpDXException e) when (e.Descriptor == SharpDX.DXGI.ResultCode.Unsupported)\n                {\n                    throw new GraphicsConfigurationException(\"The Desktop Duplication API is not supported on this computer.\", e);\n                }\n                catch (SharpDXException e) when (e.Descriptor == SharpDX.DXGI.ResultCode.InvalidCall)\n                {\n                    throw new GraphicsConfigurationException(\"The Desktop Duplication API is not supported on this screen.\", e);\n                }\n                catch (SharpDXException e) when (e.Descriptor.NativeApiCode == \"E_INVALIDARG\")\n                {\n                    throw new GraphicsConfigurationException(\"Looks like that the Desktop Duplication API is not supported on this screen.\", e);\n                }\n            }\n        }\n    }\n\n    /// <summary>\n    /// Get the correct Output1 based on region to be captured.\n    /// </summary>\n    private Output1 GetOutput(Factory1 factory)\n    {\n        try\n        {\n            //Gets the output with the bigger area being intersected.\n            var output = factory.Adapters1.SelectMany(s => s.Outputs).FirstOrDefault(f => f.Description.DeviceName == DeviceName) ??\n                         factory.Adapters1.SelectMany(s => s.Outputs).OrderByDescending(f =>\n                         {\n                             var x = Math.Max(Left, f.Description.DesktopBounds.Left);\n                             var num1 = Math.Min(Left + Width, f.Description.DesktopBounds.Right);","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif/Capture/DirectImageCapture.cs#L184-L220","documentation":"Thrown by DirectImageCapture when DuplicateOutput raises a SharpDXException whose Descriptor.NativeApiCode is 'E_INVALIDARG'. This is a low-level COM/DXGI error indicating an invalid argument was passed to the duplication call — functionally similar to the InvalidCall case but surfaced through a different error code path.","triggerScenarios":"DuplicateOutput receives a Device or Output1 argument that DXGI rejects at the native level. This can happen with mismatched device/output adapters, a null or disposed Device, or an output that was invalidated between enumeration and the duplication call.","commonSituations":"Same root causes as error [18]: hybrid GPU mismatch, monitor disconnected/reconnected, device created on wrong adapter. The NativeApiCode 'E_INVALIDARG' is the raw HRESULT form of the error, suggesting an older driver or a DXGI version that maps the failure to this code rather than InvalidCall.","solutions":["Ensure Device and Output1 are from the same adapter — verify with output1.Adapter.Description matches the device's adapter.","Re-create the Device from the correct adapter before calling DuplicateOutput.","Update graphics drivers to ensure DXGI error codes are mapped correctly.","Fall back to BitBlt capture when DDA fails with E_INVALIDARG."],"exampleFix":"// before\ncatch (SharpDXException e) when (e.Descriptor.NativeApiCode == \"E_INVALIDARG\")\n{\n    throw new GraphicsConfigurationException(\"Looks like that the Desktop Duplication API is not supported on this screen.\", e);\n}\n\n// after: log adapter mismatch details for diagnosis\ncatch (SharpDXException e) when (e.Descriptor.NativeApiCode == \"E_INVALIDARG\")\n{\n    LogWriter.Log($\"DDA E_INVALIDARG: Device adapter={Device.Adapter.Description.Description}, Output adapter={output1.Adapter.Description.Description}\");\n    throw new GraphicsConfigurationException(\"The Desktop Duplication API is not supported on this screen (adapter mismatch).\", e);\n}","handlingStrategy":"validation","validationCode":"// Verify adapter match before DuplicateOutput\nif (Device.Adapter.Interface.Parent != output1.Adapter.Interface.Parent)\n{\n    Device.Dispose();\n    Device = new SharpDX.Direct3D11.Device(output1.Adapter);\n}","typeGuard":"static bool AreAdaptersCompatible(Device device, Output1 output)\n{\n    return device.Adapter.Description.Description == output.Adapter.Description.Description;\n}","tryCatchPattern":"try\n{\n    DuplicatedOutput = output1.DuplicateOutput(Device);\n}\ncatch (GraphicsConfigurationException ex) when (ex.InnerException is SharpDXException sde\n    && sde.Descriptor.NativeApiCode == \"E_INVALIDARG\")\n{\n    Device = new SharpDX.Direct3D11.Device(output1.Adapter);\n    DuplicatedOutput = output1.DuplicateOutput(Device);\n}","preventionTips":["Always match the DirectX Device adapter to the target output's adapter before calling DuplicateOutput.","Log detailed adapter information when E_INVALIDARG occurs to diagnose the mismatch.","Fall back to BitBlt capture if DDA fails with E_INVALIDARG after adapter correction."],"tags":["dxgi","desktop-duplication","screen-capture","sharpdx","e-invalidarg"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}