Exception catches in CSLA

Exception catches in CSLA

Old forum URL: forums.lhotka.net/forums/t/5242.aspx


sixeyes posted on Thursday, August 14, 2008

Rocky,

My boss has just spent several hours trying to track down the source of an exception which only occurs on his machine. The exception stacktrace didn't report the location of the initial exception. If this error had occurred at a customer we've not got much to go on in the reported exception

I would like to know why CSLA doesn't wrap the caught exception.

I thought wrapping the caught exception was standard .NET behaviour?

Iain

triplea replied on Thursday, August 14, 2008

Out of curiosity, what type of exception was thrown? And are you sure you didn't rethrow it yourself(s) somewhere along the process and accidently loosing the stack trace?

sixeyes replied on Monday, August 18, 2008

In the default CSLA v3.5.1 code I catch the following exception

--------------------------------------------------------------------------------
Exception Type:       Csla.PropertyLoadException
Exception message:    Property load or set failed for property Id (Validation rule rule://DoesDatabaseExistAndIsCorrectVersion/Id failed in property Id)
Exception stacktrace:
   at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo`1 propertyInfo, P newValue, NoAccessBehavior noAccess) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Core\BusinessBase.cs:line 2152
   at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo`1 propertyInfo, P newValue) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Core\BusinessBase.cs:line 2049
   at Centurion.Marsc.Business.Data.Master.CurrentChildDatabase.set_Id(Int32 value) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Business\Data\Master\CurrentChildDatabase.cs:line 25
   at Centurion.Marsc.Business.Data.Master.CurrentChildDatabase.DataPortal_Fetch(SingleCriteria`2 criteria) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Business\Data\Master\CurrentChildDatabase.cs:line 152
   at dm(Object , Object[] )
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Reflection\MethodCaller.cs:line 221
--------------------------------------------------------------------------------


However if I make sure that the exception caught in Csla\Core\BusinessBase:2152 actually wraps the caught exception I get the following exceptions reported

--------------------------------------------------------------------------------
Exception Type:       Csla.PropertyLoadException
Exception message:    Property load or set failed for property Id (Validation rule rule://DoesDatabaseExistAndIsCorrectVersion/Id failed in property Id)
Exception stacktrace:
   at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo`1 propertyInfo, P newValue, NoAccessBehavior noAccess) in g:\centurion\projects\marketing\3rdparty\cslacs\csla\core\BusinessBase.cs:line 2152
   at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo`1 propertyInfo, P newValue) in g:\centurion\projects\marketing\3rdparty\cslacs\csla\core\BusinessBase.cs:line 2049
   at Centurion.Marsc.Business.Data.Master.CurrentChildDatabase.set_Id(Int32 value) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Business\Data\Master\CurrentChildDatabase.cs:line 25
   at Centurion.Marsc.Business.Data.Master.CurrentChildDatabase.DataPortal_Fetch(SingleCriteria`2 criteria) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Business\Data\Master\CurrentChildDatabase.cs:line 152
   at dm(Object , Object[] )
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Reflection\MethodCaller.cs:line 221

                    ----------------------------------------

Exception Type:       Csla.Validation.ValidationException
Exception message:    Validation rule rule://DoesDatabaseExistAndIsCorrectVersion/Id failed in property Id
Exception stacktrace:
   at Csla.Validation.ValidationRules.CheckRules(List`1 list) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Validation\ValidationRules.cs:line 1011
   at Csla.Validation.ValidationRules.CheckRules(String propertyName) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Validation\ValidationRules.cs:line 926
   at Csla.Core.BusinessBase.PropertyHasChanged(String propertyName) in g:\centurion\projects\marketing\3rdparty\cslacs\csla\core\BusinessBase.cs:line 285
   at Csla.Core.BusinessBase.LoadPropertyValue[P](PropertyInfo`1 propertyInfo, P oldValue, P newValue, Boolean markDirty) in g:\centurion\projects\marketing\3rdparty\cslacs\csla\core\BusinessBase.cs:line 2345
   at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo`1 propertyInfo, P newValue, NoAccessBehavior noAccess) in g:\centurion\projects\marketing\3rdparty\cslacs\csla\core\BusinessBase.cs:line 2148

                    ----------------------------------------

Exception Type:       System.ArgumentException
Exception message:    Keyword not supported: 'fireflash\sql2005;user'.
Exception stacktrace:
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value)
   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at Centurion.Marsc.Data.DataAccess.MarscDataAccessBase..ctor(MarscConnectionInfo connectionInfo) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Data\DataAccess\MarscDataAccessBase.cs:line 26
   at Centurion.Marsc.Data.DataAccess.MarscDataAccessSQL..ctor(MarscConnectionInfo dbConnectionInfo) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Data\DataAccess\MarscDataAccessSQL.cs:line 11
   at Centurion.Marsc.Data.DataAccess.MarscDataAccessFactory.GetDataAccess(MarscConnectionInfo connectionInfo) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Data\MarscDataAccessFactory.cs:line 16
   at Centurion.Marsc.Data.MarscDataLayer.SetChildConnectionInfo(Int32 databaseId) in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Data\MarscDataLayer.cs:line 430
   at Centurion.Marsc.Business.Data.Master.ChildDatabaseVersion.DataPortal_Execute() in G:\Centurion\Projects\Marketing\Trunk\Centurion\Marsc\Business\Data\Master\ChildDatabaseVersion.cs:line 36
   at dm(Object , Object[] )
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in G:\Centurion\Projects\Marketing\3rdParty\cslacs\Csla\Reflection\MethodCaller.cs:line 221
--------------------------------------------------------------------------------

Fixing the problem was easy once the last exception was seen:

Exception Type:       System.ArgumentException
Exception message:    Keyword not supported: 'fireflash\sql2005;user'.

However this information is lost because it's not wrapped by the exception in Csla\Core\BusinessBase

Iain

ajj3085 replied on Monday, August 18, 2008

Good catch.  It looks like this is done on some other lines as well.  The only issue I could see with wrapping the exception though is if it crosses the dataportal boundary.. if it's a remote server and the wrapped exception isn't Serializable, you won't get the exception.

sixeyes replied on Monday, August 18, 2008

Good point. All my exceptions are marked Serializable as I had assumed they were being wrapped.

Perhaps we could have some handy code to check and only wrap remote exceptions if they're Serializable?

Iain

ajj3085 replied on Monday, August 18, 2008

Ya, I mark all of mine as well, but I think some in the .Net framework itself aren't marked as such.  But it may not be an issue at all anyway, since SetProperty runs on the client AFAICT.

RockfordLhotka replied on Tuesday, August 19, 2008

Added to list of bugs

http://www.lhotka.net/cslabugs/edit_bug.aspx?id=90

Copyright (c) Marimer LLC