CSLA 4.0 RC0 Breaking Issues.CSLA 4.0 RC0 Breaking Issues.
Old forum URL: forums.lhotka.net/forums/t/9220.aspx
bniemyjski posted on Friday, July 16, 2010
Hello,
I recently tried upgrading our CodeSmith samples from CSLA 3.8.4 to CSLA 4.0 and ran into a bunch of unit tests that are no longer working and the code in question hasn't changed.
The first breaking issue is that LoadProperty throws an exception:
6. Updating the non Identity Primary Key.
Getting lineItem "359"
Csla.DataPortalException : DataPortal.Fetch failed (Member not found on object (OriginalOrderId))
----> Csla.Reflection.CallMethodException : DataPortal_Fetch method call failed
----> System.InvalidOperationException : Member not found on object (OriginalOrderId)
at
Csla.Reflection.MethodCaller.
GetCachedProperty(
Type objectType,
String propertyName)
at
Csla.Reflection.MethodCaller.
CallPropertySetter(
Object obj,
String property,
Object value)
at
Csla.Core.BusinessBase.
LoadProperty(
IPropertyInfo propertyInfo,
Object newValue)
at
PetShop.Tests.ParameterizedSQL.LineItem.
Map(
SafeDataReader reader) in
LineItem.DataAccess.cs: line 458at
PetShop.Tests.ParameterizedSQL.LineItem.
DataPortal_Fetch(
LineItemCriteria criteria) in
LineItem.DataAccess.cs: line 57at
lambda_method(
Closure,
Object,
Object[])
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters)
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters)
at
Csla.Server.SimpleDataPortal.
Fetch(
Type objectType,
Object criteria,
DataPortalContext context)
at
Csla.DataPortal.
Fetch(
Type objectType,
Object criteria)
at
Csla.DataPortal.
Fetch(
Object criteria)
at
PetShop.Tests.ParameterizedSQL.LineItem.
GetByOrderId(
Int32 orderId) in
LineItem.Generated.cs: line 158at
PetShop.Tests.ParameterizedSQL.LineItemTests.
Step_06_UpdatePrimaryKey() in
LineItemTests.cs: line 256
Upon looking into the error. I noticed that some core code was changed in trunk that doesn't allow for non public properties!!!!
Steps to reproduce:
LoadProperty(_itemIdProperty, 0);
private static readonly PropertyInfo< System.Int32 > _originalOrderIdProperty = RegisterProperty< System.Int32 >(p => p.OriginalOrderId, string.Empty);
/// <summary>
/// Holds the original value for OrderId. This is used for non identity primary keys.
/// </summary>
internal System.Int32 OriginalOrderId
{
get { return GetProperty(_originalOrderIdProperty); }
set{ SetProperty(_originalOrderIdProperty, value); }
}
The second bug is that when you have an EditableRootList and your child is a switchable object. You get the following exception.
3. Selecting all categories by calling GetByCategoryId("WJEBQOILVU").
Csla.DataPortalException : DataPortal.Fetch failed (List item must be marked as a child object)
----> Csla.Reflection.CallMethodException : Fetch method call failed
----> System.InvalidOperationException : List item must be marked as a child object
at
Csla.BusinessListBase`2.
InsertItem(
Int32 index,
C item)
at
PetShop.Tests.ObjF.StoredProcedures.DAL.CategoryListFactory.
Fetch(
CategoryCriteria criteria) in
CategoryListFactory.DataAccess.cs: line 85at
lambda_method(
Closure,
Object,
Object[])
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters)
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters)
at
Csla.Server.FactoryDataPortal.
InvokeMethod(
String factoryTypeName,
String methodName,
Object e,
DataPortalContext context)
at
Csla.Server.FactoryDataPortal.
Fetch(
Type objectType,
Object criteria,
DataPortalContext context)
at
Csla.DataPortal.
Fetch(
Type objectType,
Object criteria)
at
Csla.DataPortal.
Fetch(
Object criteria)
at
PetShop.Tests.ObjF.StoredProcedures.CategoryList.
GetByCategoryId(
String categoryId)
in
CategoryList.Generated.cs: line 70at
PetShop.Tests.ObjF.StoredProcedures.CategoryTests.
Step_03_SelectAll() in
CategoryTests.cs: line 146
Please note that these same scenarios and code in question is the exact same from CSLA 3.8.4 and CSLA 4.0 RC0 but RC0 throws an exception!!!
Thanks
-Blake Niemyjski
RockfordLhotka replied on Friday, July 16, 2010
1. The LoadProperty change has been redone post RC0 - please grab the current code from svn and see if this issue persists - but it should not, because the non-generic LoadProperty now uses reflection to invoke the generic LoadProperty, instead of invoking the property setter (which it did in RC0).
2 and 3. This is an intentional change to help people avoid bugs that may occur when they add a root object to a BLB collection. BLB is designed to work with child objects, so this change just ensures that only child objects can be added to a BLB.
In other words, your existing code/template probably has a bug where it is creating the "child" object not as a child, and is then adding it to a BLB.
bniemyjski replied on Wednesday, July 28, 2010
Hello,
I just verified that this is still an issue with CSLA 4.0.0.
Here is the exception message I get:
Test method TestProject1.UnitTest1.GetClient threw exception:
Csla.DataPortalException: DataPortal.Fetch failed (Member not found on object (OriginalOid)) ---> Csla.Reflection.CallMethodException: DataPortal_Fetch method call failed ---> System.InvalidOperationException: Member not found on object (OriginalOid)
at
Csla.Reflection.MethodCaller.
GetCachedProperty(
Type objectType,
String propertyName) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 205at
Csla.Reflection.MethodCaller.
CallPropertySetter(
Object obj,
String property,
Object value) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 278at
Csla.Core.BusinessBase.
LoadProperty(
IPropertyInfo propertyInfo,
Object newValue) in
C:\Visual Studio
Projects\csla\Source\Csla\Core\BusinessBase.cs: line 2460at
ClientTest.Business.Client.
Map(
SafeDataReader reader) in
Client.DataAccess.cs: line 248at
ClientTest.Business.Client.
DataPortal_Fetch(
ClientCriteria criteria) in
Client.DataAccess.cs: line 56at
lambda_method(
Closure,
Object,
Object[])
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 434--- End
of inner exception stack trace ---
at
Csla.Reflection.MethodCaller.
GetCachedProperty(
Type objectType,
String propertyName) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 205at
Csla.Reflection.MethodCaller.
CallPropertySetter(
Object obj,
String property,
Object value) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 278at
Csla.Core.BusinessBase.
LoadProperty(
IPropertyInfo propertyInfo,
Object newValue) in
C:\Visual Studio
Projects\csla\Source\Csla\Core\BusinessBase.cs: line 2460at
ClientTest.Business.Client.
Map(
SafeDataReader reader) in
Client.DataAccess.cs: line 248at
ClientTest.Business.Client.
DataPortal_Fetch(
ClientCriteria criteria) in
Client.DataAccess.cs: line 56at
lambda_method(
Closure,
Object,
Object[])
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 434at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 438at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
String method,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 347at
Csla.Reflection.LateBoundObject.
CallMethod(
String method,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\LateBoundObject.cs: line 93at
Csla.Server.SimpleDataPortal.
Fetch(
Type objectType,
Object criteria,
DataPortalContext context) in
C:\Visual Studio
Projects\csla\Source\Csla\Server\SimpleDataPortal.cs: line 133--- End
of inner exception stack trace ---
at
Csla.Reflection.MethodCaller.
GetCachedProperty(
Type objectType,
String propertyName) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 205at
Csla.Reflection.MethodCaller.
CallPropertySetter(
Object obj,
String property,
Object value) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 278at
Csla.Core.BusinessBase.
LoadProperty(
IPropertyInfo propertyInfo,
Object newValue) in
C:\Visual Studio
Projects\csla\Source\Csla\Core\BusinessBase.cs: line 2460at
ClientTest.Business.Client.
Map(
SafeDataReader reader) in
Client.DataAccess.cs: line 248at
ClientTest.Business.Client.
DataPortal_Fetch(
ClientCriteria criteria) in
Client.DataAccess.cs: line 56at
lambda_method(
Closure,
Object,
Object[])
at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 434at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
DynamicMethodHandle methodHandle,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 438at
Csla.Reflection.MethodCaller.
CallMethod(
Object obj,
String method,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\MethodCaller.cs: line 347at
Csla.Reflection.LateBoundObject.
CallMethod(
String method,
Object[]
parameters) in
C:\Visual Studio
Projects\csla\Source\Csla\Reflection\LateBoundObject.cs: line 93at
Csla.Server.SimpleDataPortal.
Fetch(
Type objectType,
Object criteria,
DataPortalContext context) in
C:\Visual Studio
Projects\csla\Source\Csla\Server\SimpleDataPortal.cs: line 133at
Csla.DataPortal.
Fetch(
Type objectType,
Object criteria) in
C:\Visual Studio
Projects\csla\Source\Csla\DataPortal.cs: line 245at
Csla.DataPortal.
Fetch(
Object criteria) in
C:\Visual Studio
Projects\csla\Source\Csla\DataPortal.cs: line 170at
ClientTest.Business.Client.
GetByOid(
String oid) in
Client.Generated.cs: line 353at
TestProject1.UnitTest1.
GetClient() in
UnitTest1.cs: line 67
This code throws an exception:
private static readonly PropertyInfo< System.String > _originalOidProperty = RegisterProperty< System.String >(p => p.OriginalOid, string.Empty);
/// <summary>
/// Holds the original value for Oid. This is used for non identity primary keys.
/// </summary>
internal System.String OriginalOid
{
get { return GetProperty(_originalOidProperty); }
set{ SetProperty(_originalOidProperty, value); }
}
This code works:
private static readonly PropertyInfo< System.String > _originalOidProperty = RegisterProperty< System.String >(p => p.OriginalOid, string.Empty);
/// <summary>
/// Holds the original value for Oid. This is used for non identity primary keys.
/// </summary>
public System.String OriginalOid
{
get { return GetProperty(_originalOidProperty); }
set{ SetProperty(_originalOidProperty, value); }
}
using(BypassPropertyChecks)
{
LoadProperty(_oidProperty, reader["OID"]);
LoadProperty(_originalOidProperty, reader["OID"]);
}
Thanks
-Blake Niemyjski
RockfordLhotka replied on Wednesday, July 28, 2010
This issue is unrelated to the RC0 LoadProperty() change then, because that was undone in RC1 and RTM - the non-generic LoadProperty() is completely unlike the RC0 implementation.
bniemyjski replied on Thursday, July 29, 2010
Hello,
Yes, I think that this issue and the lambda issue (already logged) should be worked out before 4.0.1.
Thanks
-Blake Niemyjski
RockfordLhotka replied on Thursday, July 29, 2010
I guess what I was trying to say in my previous post is that I don't know what this issue actually is. I don't have a unit test repro for it (?).
bniemyjski replied on Thursday, July 29, 2010
Hello,
I know the issue and the fix. I'll create a unit test for it and get the tests committed. There is some reflection code that only checks to see if it is a public property, it doesn't check to see if a property exists that is also internal or private..
Thanks
-Blake Niemyjski
bniemyjski replied on Sunday, August 01, 2010
Hello,
I added some more unit tests for this load property issue and couldn't reproduce. I'll take another look at the sample application.
Thanks
-Blake Niemyjski
akhil replied on Thursday, August 19, 2010
hello,
how can we over come with this issue..?
help me.
bniemyjski replied on Thursday, August 19, 2010
Hello,
This has been fixed in 4.0 RTM. Please make sure your references are correct and that you download the latest version from the site.
Thanks
-Blake Niemyjski
Copyright (c) Marimer LLC