{"record":{"id":"36bc63b3e455ffac","repo":"dotnet/wpf","slug":"sr-callbackparameterinvalid","errorCode":null,"errorMessage":"SR.CallbackParameterInvalid","messagePattern":"SR\\.CallbackParameterInvalid","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs","lineNumber":752,"sourceCode":"        /// <param name=\"param\">\n        /// Caller-supplied parameter to EnumUseLicenseStreams. In this case, it is a\n        /// LoadUseLicenseForUserParams object.\n        /// </param>\n        /// <param name=\"stop\">\n        /// Set to true if the callback function wants to stop the enumeration. This callback\n        /// function never wants to stop the enumeration, so this parameter is not used.\n        /// </param>\n        private void\n        LoadUseLicenseForUser(\n            RightsManagementEncryptionTransform rmet,\n            StreamInfo si,\n            object param,\n            ref bool stop\n            )\n        {\n            if (param is not LoadUseLicenseForUserParams lulfup)\n            {\n                throw new ArgumentException(SR.CallbackParameterInvalid, nameof(param));\n            }\n\n            ContentUser userDesired = lulfup.User;\n            Debug.Assert(userDesired != null);\n\n            ContentUser userFromStream = null;\n            using (Stream stream = si.GetStream(FileMode.Open, FileAccess.Read))\n            {\n                using (BinaryReader utf8Reader = new BinaryReader(stream, Encoding.UTF8))\n                {\n                    userFromStream = rmet.LoadUserFromStream(utf8Reader);\n\n                    if (userFromStream.GenericEquals(userDesired))\n                    {\n                        lulfup.UseLicense = rmet.LoadUseLicenseFromStream(utf8Reader);\n                        stop = true;\n                    }\n                }","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs#L734-L770","documentation":"LoadUseLicenseForUser runs as a stream callback and expects its 'param' to be a LoadUseLicenseForUserParams instance carrying the desired user. Any other object type is rejected with ArgumentException (SR.CallbackParameterInvalid) naming 'param'. It is an internal callback contract violation.","triggerScenarios":"Invoking the callback path with a param object that is not LoadUseLicenseForUserParams — typically only via incorrect internal/reflection-driven calls or a mismatched callback registration.","commonSituations":"Custom code (or tests) invoking the internal enumeration callback directly with wrong payload; version mismatch where the params wrapper type changed between assemblies.","solutions":["Pass a properly constructed LoadUseLicenseForUserParams containing the target ContentUser","Use the public useLicense-for-user API instead of invoking the callback directly","Rebuild against matching WindowsBase versions so callback types line up","In tests, mimic the exact callback signature and payload type"],"exampleFix":"// before\ntransform.EnumerateStreams(callback, user); // wrong payload type\n// after\nvar param = new LoadUseLicenseForUserParams(user);\ntransform.EnumerateStreams(callback, param);","handlingStrategy":"type-guard","validationCode":"if (param is not LoadUseLicenseForUserParams p) throw new ArgumentException(\"Callback param must be LoadUseLicenseForUserParams\", nameof(param));","typeGuard":"bool IsValidCallbackParam(object param) => param is LoadUseLicenseForUserParams { User: not null };","tryCatchPattern":"try { callback(streamInfo, param, ref stop); } catch (ArgumentException ex) when (ex.ParamName == \"param\") { /* fix payload type */ }","preventionTips":["Always wrap the desired user in LoadUseLicenseForUserParams before invoking the callback","Call public APIs instead of internal callbacks","Keep test harnesses in sync with WindowsBase versions"],"tags":["wpf","rights-management","argument-exception","callback"],"backgroundTag":"invalid-argument-value","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"}