PDA

View Full Version : Strange exception message error in SpEL


john.hui
03-10-2007, 09:00 AM
Hi Spring Team,

I am trying to invoke a property within SpEL but I have met with some difficulties. I have tried to simplify everything to isolate the crux of the matter.

I have the following class:


Public Class Test

Public Shared ReadOnly Property TestProperty(ByVal str As String) As String
Get
Return "Success"
End Get
End Property
End Class


I want to invoke the TestProperty property within an SpEL.

So I execute the following line of code:


obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "Test.TestProperty('hello')")


I get an ArgumentException exception with the message:
"Method with a specified number and types of arguments does not exist."

So I tried again with the following line of code:

obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "Test.TestProperty['hello']")


I get an InvalidProgramException exception with the message:

"Common Language Runtime detected an invalid program."

Source: "Spring.DynamicReflection"

StackTrace: " at Spring.DynamicReflection.Property_TestProperty_29a 3cb00b4f74c8abc00045102c29fa7.GetValue(Object target)
at Spring.Util.DynamicReflection.SafeProperty.GetValu e(Object target)
at Spring.Expressions.PropertyOrFieldNode.PropertyVal ueAccessor.Get(Object context)
at Spring.Expressions.PropertyOrFieldNode.GetProperty OrFieldValue(Object context)
at Spring.Expressions.PropertyOrFieldNode.Get(Object context, IDictionary variables)
at Spring.Expressions.BaseNode.GetValue(Object context, IDictionary variables)
at Spring.Expressions.Expression.Get(Object context, IDictionary variables)
at Spring.Expressions.BaseNode.GetValue(Object context, IDictionary variables)
at Spring.Expressions.ExpressionEvaluator.GetValue(Ob ject root, String expression)
at Main.Main.Main() in E:\PAC\20070306 with BuyerGroupsFactoryMgr\Main\Main.vb:line 103
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()"

I need some help here to understand what is happenning. This is the first time I have seen a "Common Language Runtime detected an invalid program." exception message.

Thanks in advance.

John Hui

Erich Eichinger
03-10-2007, 04:10 PM
Hi John,

Remember that SpEL syntax is more like C# than VB. Your first expression evaluates to a function call, your second expression evaluates to an indexer-call.

The correct solution of querying a property-value would simple be

mytext = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "Test.TestProperty")


I agree that the latter exception should not occur. It happens, because internally IL-code is generated to access an indexer Test.TestProperty[], but at runtime the CLR detects only a simple property with that name.

hope this helps,
Erich

john.hui
03-10-2007, 09:49 PM
Hi Erich,

Thank you for your reply.

The property requires me to pass a parameter value. The solution you provided does not show me how I can do this. What is the correct way of doing this using SpEL?

Thanks.

John

Erich Eichinger
03-10-2007, 10:40 PM
Hi John,

I'm pretty sure that we don't support this yet but I will ask Aleks to be sure (he has done most of SpEL) - in fact I even didn't know that in VB it is possible to pass additional parameters to a property getter/setter.

I added a JIRA issue SPRNET-503 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-503) to remind us.

cheers,
Erich