Exception in ToString method of UnsignedPublicLicense RRS feed

  • Question

  • Hello,

    I am developing an application using the classes/methods of System.Security.RighstManagement. I have a user interface where the end-user configures a rights management policy with specific rights (edit, print, etc.). After the user enters the rights, I just want to save the policy to an XrML file. For that I am using the method ToString() of UnsignedPublicLicense.

    To setup the UnsignedPublicLicense, I add grants using ContentGrant() method. If I use ContentGrant(ContentUser, ContentRight) to set the grants, the results is fine and I get the XrML. If I use ContentGrant(ContentUser, ContentRight, DateTime, DateTime) with the DateTime.MinValue and DateTime.MaxValue (this is, no date restriction) it also works fine. The problem is that when I try to put a limit on the dates (see example below) it throws an exception ("Rights Management operation failed") in the UnsingedPublicLicense.ToString() method.

    Am I am doing anything wrong?

    Example of the code:
    public void buildUnsignedPublishLicense()
       UnsignedPublishLicense unsignedLicense = new UnsignedPublishLicense();

       // Set an empty Guid for the policy
       unsignedLicense.ContentId = new Guid();
       // Set Owner
       unsignedLicense.Owner = new ContentUser(_currentUserId, AuthenticationType.Windows);

       // Set rights for other user
       ContentUser user = new ContentUser(this._user_perm_list[0].UserId, AuthenticationType.Windows);

       // Set expiration date
       DateTime validFrom = DateTime.MinValue;
       DateTime validUntil = new DateTime(2010, 12, 12);
       //DateTime validUntil = DateTime.MaxValue; --> With this validUntil date the result is fine and I see the XrML printed.

       // Set Grants
       ContentGrant grant = new ContentGrant(user, ContentRight.DocumentEdit, validFrom, validUntil);

       // Show XrML of Unsigned Publish License
       MessageBox.Show("Unsigned Publish License: " + unsignedLicense.ToString());


    Tuesday, November 30, 2010 2:57 PM