A common bug in .Net 2.0 may cause the following exception when compiling a proxy:
Microsoft did not fix this bug for Wcf so it also gives a similar exception:
Is this error limited to DateTime?
Not at all. You may also get any of these:
Or with your custom types.
What does this error mean?
For you – nothing. This is a .Net/Wcf bug.
When does this happen?
When the following conditions apply:
1. The wsdl (schema) declares a complex type C.
2. C contains a single element with maxOccures>1 (an array).
3. The wsdl declares an element e of type X with maxOccures>1.
What is the .Net bug?
The proxy will generate something like this:
This line declares an array of type DateTime, but also specifies that each item of the array is of type DateTime. Which is clearly an error since the array items are of type DateTime (this is a multidimentional array).
This is the reason why the proxy does not compile.
Limitation: This change will be overridden every time you regenerate the proxy (update web/service reference).
We mentioned that the bug only happens when the type C has one child element. Why not add it some friend so it would not be alone? This means we need to manually edit the wsdl. For example:
Now you may say this changes the schema and makes our proxy not valid. But note we have added an optional field only (minOccurs=0) so as long as we do not assign any value to it in our client this change is non-breaking.
Now let’s see how the proxy generated from the updated wsdl looks like:
Now .Net does not generate the multidimensional array in one shot, but declares the mediating type C. The proxy will in turn use this type as an array:
which gives us the multidimensional effect.
This compiles immediately so we’re free to go.