Open RIA Services User Support The code generation fails if an EntityObject class is decorated with custom attribute  Viewed 11167 time(s), 1 post(s)., 10/20/2014 7:21:22 PM - by Juice

Juice 10/20/2014 7:21:22 PM

In my data model I would like to decorate certain EntityObject types with a custom attribute on the server-side. I added my custom attribute to a derived EntityObject in its custom partial class declaration. Alas, when I did this, my rebuild failed because the code generation failed with the following error:
The code generator 'OpenRiaServices.DomainServices.Tools.CSharpCodeDomClientCodeGenerator' encountered a fatal exception and could not generate code for project '<path to client-side project>':
Object reference not set to an instance of an object.

If I do nothing else than comment my custom attribute from the partial class, the rebuild goes through.
After investigating the issue more closely, I found out that the problem is probably that the attribute constructor has params array as an argument. If I have an array field (string[], Type[] etc.) declared in my attribute AND I try to initialize its value in either the field declaration itself or in my constructor, the code generator fails.
Here is a sample class Attribute to test with. This should break code generation as it is now, but if one comments both the field initialization in its declaration and contents of the constructor, code generation goes through.

public class MyAttribute : Attribute
    private Type[] _interfaces = Type.EmptyTypes;
    public MyAttribute(params Type[] interfaces)
        Interfaces = interfaces.Where(i => i.IsInterface).ToArray();
    public Type[] Interfaces
        get { return _interfaces; }
        private set { _interfaces = value; }

I have OpenRiaServices.Silverlight.CodeGen. (where the OpenRiaServices.DomainServices.Tools.dll is found) and other packages are of version.

This content has not been rated yet. 
15 Reputation 1 Total posts