{"record":{"id":"af946edbdd54d82c","repo":"dotnet/wpf","slug":"sr-penservice-invalidpacketdata","errorCode":null,"errorMessage":"SR.PenService_InvalidPacketData","messagePattern":"SR\\.PenService_InvalidPacketData","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs","lineNumber":783,"sourceCode":"            }\n\n            return false;\n        }\n\n        /////////////////////////////////////////////////////////////////////\n\n        internal void FireEvent(PenContext penContext, int evt, int stylusPointerId, int cPackets, int cbPacket, IntPtr pPackets)\n        {\n            // disposed?\n            if (__disposed)\n            {\n                return;  // Don't process this event if we're in the process of shutting down.\n            }\n\n            // marshal the data to our cache\n            if (cbPacket % 4 != 0)\n            {\n                throw new InvalidOperationException(SR.PenService_InvalidPacketData);\n            }\n\n            int cItems = cPackets * (cbPacket / 4);\n            int[] data = null;\n            if (0 < cItems)\n            {\n                data = new int [cItems]; // GetDataArray(cItems); // see comment on GetDataArray\n                Marshal.Copy(pPackets, data, 0, cItems);\n                penContext.CheckForRectMappingChanged(data, cPackets);\n            }\n            else\n            {\n                data = null;\n            }\n\n            int timestamp = Environment.TickCount;\n            \n            // Deal with caching packet data.","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs#L765-L801","documentation":"PenThreadWorker throws InvalidOperationException (SR.PenService_InvalidPacketData) when a tablet packet stream has a per-packet byte size (cbPacket) that is not a multiple of 4. Packet data is marshaled into an int[], so non-word-aligned packet sizes cannot be processed.","triggerScenarios":"A digitizer/tablet device reporting a packet description whose cbPacket is not divisible by 4 — usually from a broken driver, non-standard HID digitizer, or corrupted pen data event arriving on the worker thread.","commonSituations":"Using obscure/cheap tablet hardware or virtualized HID devices with malformed packet descriptions; driver updates changing packet layout; remote-desktop or VM pen input bridging producing bad packet sizes.","solutions":["Update or reinstall the digitizer/tablet driver so it reports a valid packet size","Test with a standard compliant digitizer to confirm the device is the problem","Capture with WISP vs Pointer stack differences (app.config Switch.System.Windows.Input.Stylus) to route around the faulty device path","Report the device to its vendor; packet size must be a multiple of 4 bytes per packet"],"exampleFix":"// app.config — switch stylus to legacy WISP stack if Pointer stack chokes on device data\n<configuration>\n  <appSettings>\n    <add key=\"Switch.System.Windows.Input.Stylus\" value=\"Wisp\"/>\n  </appSettings>\n</configuration>","handlingStrategy":"try-catch","validationCode":"// Packet size validation happens on device data; guard the worker event\nif (cbPacket % 4 != 0) { Log.Error($\"Invalid packet size {cbPacket}\"); return; }","typeGuard":null,"tryCatchPattern":"try { ProcessPenData(cbPacket, cPackets, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"packet\")) { Log.Error(\"Bad digitizer packet size\", ex); }","preventionTips":["Keep digitizer drivers updated","Test hardware on the target framework before rollout","Consider switching the stylus stack (Wisp/Pointer) via app.config for problematic devices"],"tags":["wpf","stylus","wisp","packet-data","device-driver"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}