Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025

 


Article

GetValue used in a lambda expression throws and Object reference exception when using Visual Basic

« Go Back

Information

 
Article Number000098366
EnvironmentProduct: Sitefinity
Version: 12.x
OS: All supported OS versions
Database: All supported Microsoft SQL Server versions
Question/Problem Description
In Visual Basic when using a GetValue extension method in a lambda expression an Object reference.. error is thrown runtime. For example:
Dim testItems = dynamicModuleManager.GetDataItems(testType).Where(Function(p) p.GetValue(Of String)("Title") = "Test")
Steps to Reproduce
Clarifying Information
Error Message"Object reference not set to an instance of an object".
   at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessExpressionVisitor`2.VisitMethodCall(MethodCallExpression m)
   at Telerik.Sitefinity.Data.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b)
   at Telerik.Sitefinity.Data.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b)
   at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessExpressionVisitor`2.VisitLambda(LambdaExpression lambda)
   at Telerik.Sitefinity.Data.Linq.ExpressionVisitor.VisitUnary(UnaryExpression u)
   at Telerik.Sitefinity.Data.Linq.ExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessExpressionVisitor`2.VisitMethodCall(MethodCallExpression m)
   at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessQueryProvider`2.EnhanceExpression(Expression expression)
   at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessQueryProvider`2.CreateQuery[TElement](Expression expression)
Defect/Enhancement Number
Cause
An undocumented breaking change only applicable for Visual Basic requires casting the used object to its respective type (IDynamicFieldsContainer).
Resolution
Cast the object in the lambda expression explicitly to IDynamicFieldsContainer like so:
Dim testItems = dynamicModuleManager.GetDataItems(testType).Where(Function(p As IDynamicFieldsContainer) p.GetValue(Of String)("Title") = "Test")

 
Workaround
Notes
Attachment 
Last Modified Date9/11/2019 3:01 PM