Exception when refreshing schema and iterating over the client

Jul 25, 2013 at 2:20 PM
Edited Jul 25, 2013 at 2:21 PM

I'm writing some code to add a "Business Justification" field when joining groups. I am using the Web Client to do this.

Strangely, I get an odd error (Value was either too large or too small for an Int32) when I try and iterate over the IEnumerable returned from client.Enumerate, but I only get this error when I refresh the schema before. To explain better, look at this code

No error
using (DefaultClient client = new DefaultClient())
    foreach(RmResource res in client.Enumerate(string.Format(/"Person[(Domain='{0}' and AccountName='{1}')], this.UserDomain, this.UserAccountName))
    // Some code
With Error
using (DefaultClient client = new DefaultClient())
    foreach(RmResource res in client.Enumerate(string.Format(/"Person[(Domain='{0}' and AccountName='{1}')], this.UserDomain, this.UserAccountName)) // Iteration blows up!!
    // Some code
I have no idea why I get the exception mentioned above when I refresh the schema. I have added quite a few custom attributes to the FIM portal and I have already done an IISRESET as well, but the error message doesn't make it clear where it is blowing up.

Any clues?

Jul 31, 2013 at 7:18 AM
Never seen this one... have you updated the class definitions after you modified the schema?
Also, the stack trace would help.
Jul 31, 2013 at 9:13 AM
Hi Paolo,

I didn't modify the class definitions since I'm not building the assemblies from source, instead I'm just using the DLL's directly.
Having said that, it only blows up on one particular FIM implementation and works fine on the others, I'll try and get the stack trace and post it here.

Aug 9, 2013 at 1:38 PM
Check your client's binding property: maxReceivedMessageSize

This is a pretty common error when enumerating a large number of results. If you try to perform an XPath such as "/Request" or "/*", that will return more than the default 65K bytes for the message.
Mar 7, 2014 at 8:59 AM

I've been facing the same issue yesterday, and I think I found out a kind of a solution.
After printing the stack trace, I got that an OverflowException is thrown from Microsoft.ResourceManagement.Client.RmresourceFactory.ConstructAttributeValue.
Here is the bunch of code that raises the exception :
                switch (info.AttributeType)
                    case RmAttributeType.String:
                        return innerText;
                    case RmAttributeType.DateTime:
                        return DateTime.Parse(innerText);
                    case RmAttributeType.Integer:
                        return Int32.Parse(innerText);
                    case RmAttributeType.Reference:
                        return new RmReference(innerText);
                    case RmAttributeType.Binary:
                        return new RmBinary(innerText);
                    case RmAttributeType.Boolean:
                        return Boolean.Parse(innerText);
                        return innerText;
Int32.Parse(innerText) is what we are looking for. Indeed, after getting the attribute type, ConstructAttributeValue try to set the value in the right type. But the argument you're trying to extract is too large for the Int32 structure. Then, you have two solutions :
  1. You redefine your attribute in oder it never overflows an Int32.
  2. You replace the Int32 struct by a Int64 struct or much larger type.
In the first case, just do a catch statement with the following code :
            catch (System.OverflowException oe)
                throw new ArgumentException(
                        "Failed to parse attribute {0} with value {1} into type {2}. Overflows.",
This way, you can get the name of the attribute that raises the exception.

Hope it will help,


PS : Sorry for my english, it's been a long time I did not practice.