I'm trying to export some portion of the AdditionalRights of a Document to a text file. I get the following error

Attempted to read or write protected memory

When I run the following test code:

DocumentAccessRightsCollection2 collection = (DocumentAccessRightsCollection2)doc.AdditionalRig hts;

foreach (DocumentAccessRights rights in collection)
writer.WriteLine("{0}", rights.User.EMailAddress);

A debug session of stepping through the code has the cursor going to collection in the foreach statement then to in. The next step takes it to the catch block where I pick up the exception error.

The program is configured as a trusted application and I'm using various accounts as test cases. All of them give me this error.