This project is read-only.

More than 30 classes decorated with [Validate] triggers PostSharp error


Invariably, when I hit 31 (anything more than 30) classes decorated with [Validate], I get the following when I try to compile:
Error 1 Unhandled exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at PostSharp.CodeWeaver.Weaver.WeaveMethod(MethodDefDeclaration method)
at PostSharp.CodeWeaver.Weaver.Weave()
at PostSharp.CodeWeaver.WeaverTask.Execute()
at PostSharp.Extensibility.Project.ExecutePhase(String phase)
at PostSharp.Extensibility.Project.Execute()
at PostSharp.Extensibility.PostSharpObject.ExecuteProjects()
at PostSharp.Extensibility.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation)
at PostSharp.MSBuild.PostSharpRemoteTask.Execute(PostSharpTaskParameters parameters, TaskLoggingHelper log)
Is this a known issue?


MShawnG wrote Oct 28, 2009 at 11:28 PM

After more work, I think the issue here is that all my model object inherit from a common base class, and my code was getting more than 32 advices on the same joinpoint. Modifying the SDK source (is there a better way) so that derived methods are ignored seems to have stopped the error.

mikesaunders wrote Oct 29, 2009 at 12:48 PM

Hi, I have some questions. Do you get this issue with other PostSharp aspects (not VA)? I don't think this is a VA specific issue. Was it the PostSharp SDK you modified or VA, and what version of PostSharp are you using? Thanks

MShawnG wrote Oct 29, 2009 at 2:05 PM

As of right now, I'm only using PostSharp for VA. I'm using PostSharp I was using the non-debug release of PostSharp, but switched as the Debug gave me a much more descriptive error and eventually led to my solution.

To "resolve" the issue, I modified GetInterceptionValidationMethods.ForType and rather than limit to methods that didn't derive from object, I set:

m.DeclaringType == type

Of course, that happens to work for me, but wouldn't work for everyone.

But in my case, all of my model objects derive from a generic base, ala:

MyModelObject: BaseModelObject<MyModelObject>

If I didn't decorate that BaseModelObject with a Validate attribute, PostSharp threw an error about an unrecognized method (something in ValidateAspect.GetMethodAspect was failing to find the methods in my generic base class). Decorating the generic base with [Validate] stopped that issue, but gave me the 32 advices issue (same issue I originally posted, but with a better message once I installed the PostSharp debug version).

The only guess I could come up with is that the 32 advice limit was being hit for a method in my generic base... so I modified VA to throw out inherited methods and my code started functioning again.

wrote Feb 13, 2013 at 7:03 PM