{"record":{"id":"7ec6e910fc67b8a8","repo":"dotnet/wpf","slug":"template","errorCode":null,"errorMessage":"template","messagePattern":"template","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs","lineNumber":749,"sourceCode":"        //\n        // Save temporary unsigned license and rights dictionary for signing\n        //\n\n        _temporaryRightsDictionary = rights;\n        _temporaryUnsignedPublishLicense = unsignedPublishLicense;\n    }\n\n    /// <summary>\n    /// Generates an unsigned publish license for the package from \n    /// the template.\n    /// </summary>\n    /// <param name=\"template\">\n    /// The template from which to generate a publish license</param>\n    void IRightsManagementProvider.GenerateUnsignedPublishLicense(string template)\n    {\n        if (string.IsNullOrEmpty(template))\n        {\n            throw new NullReferenceException(\"template\");\n        }\n\n        UnsignedPublishLicense unsignedPublishLicense = null;\n        // Create the license from the template.\n        unsignedPublishLicense = new UnsignedPublishLicense(template);\n\n        // Get who is currently listed as the owner of the document in the\n        // publish license\n        ContentUser currentOwnerFromLicense = null;\n        currentOwnerFromLicense = unsignedPublishLicense.Owner;\n\n        RightsManagementUser currentOwner = null;\n\n        if (currentOwnerFromLicense != null)\n        {\n            currentOwner = RightsManagementUser.CreateUser(\n                currentOwnerFromLicense);\n        }","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs#L731-L767","documentation":"RightsManagementProvider.GenerateUnsignedPublishLicense throws NullReferenceException when the 'template' string parameter is null or empty. The method requires a non-empty template string to construct an UnsignedPublishLicense, and guards this with an explicit check at the top of the method. This mirrors the underlying UnsignedPublishLicense(string) constructor's own requirement.","triggerScenarios":"Calling ((IRightsManagementProvider)provider).GenerateUnsignedPublishLicense(null) or GenerateUnsignedPublishLicense(\"\") or a whitespace-only/empty string obtained from an uninitialized configuration or resource load.","commonSituations":"Developers building rights-managed XPS documents pass a template loaded from a file or resource that failed to load (returning null), or forget to populate the template field before publishing.","solutions":["Pass a valid, non-empty publish-license template string to GenerateUnsignedPublishLicense.","Load the template from Application.GetResourceStream or a file and verify it is non-null and non-empty before calling.","If no template is needed, use the parameterless UnsignedPublishLicense constructor path instead of this API.","Correct the null-check semantics: catch NullReferenceException is not recommended; validate the input first."],"exampleFix":"// before\nprovider.GenerateUnsignedPublishLicense(template); // template may be null\n// after\nif (!string.IsNullOrEmpty(template))\n{\n    provider.GenerateUnsignedPublishLicense(template);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(template))\n    throw new ArgumentException(\"template must be a non-empty publish license template.\", nameof(template));\nprovider.GenerateUnsignedPublishLicense(template);","typeGuard":"bool IsValidTemplate(string template) => !string.IsNullOrEmpty(template);","tryCatchPattern":"try { provider.GenerateUnsignedPublishLicense(template); }\ncatch (NullReferenceException ex) { /* handle missing template input */ }","preventionTips":["Validate template with string.IsNullOrEmpty before any publish call.","Load templates through a helper that never returns null (throw early with a clear message).","Prefer ArgumentException-style guards in your own wrappers over passing raw values."],"tags":["wpf","rights-management","null-argument"],"backgroundTag":"null-argument","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"}