Hi
I have come across a problem which is a potential bug / issue in CSLA 2.1.1.4 whilst trying to DenyRead on a value displayed in a ComboBox and wanted to flag it up.
This is all in VB.Net.
I have my object (Person) binding source and a name value List (GeographicalArea) binding source set up and form utilising data binding and the tools provided within CSLA.
My person object has GeographicalAreaID as a property
My combo box is set to display a value from the Geographical Area Name value list as follows.
ComboBox.DataSource = BindingSourceGeographicalAreaList
ComboBox.DisplayMember = Value
ComboBox.ValueMember = Key
ComboBox.SelectedValue = BindingSourcePerson - GeographicalAreaID
I want to DenyRead on certain roles and have set up the Authorisation Rule as follows:-
AuthorizationRules.DenyRead(
"GeographicalAreaID", "CVS Admin")
I have a CSLA.Windows.ReadWriteAuthorization and CSLA.Windows.BindingSourceRefresh on the form linked to the Person Binding Source as required
The Geographical Area Combo Box is set to Apply Authorisation on the ReadWriteAuthorisation
When I Access the form as a user in the Role 'CVS Admin' - I get an exception whilst internally trying to set the SelectedValue on the ComboBox.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.Windows.Forms.CurrencyManager.Find(PropertyDescriptor property, Object key, Boolean keepIndex)
at System.Windows.Forms.ListControl.set_SelectedValue(Object value)
--- End of inner exception stack trace ---
I traced it to the ApplyReadRules Routine in ReadWriteAuthorization.vb at the point when the control is disabled and the code tries to SetValue on the PropertyInfo.
If propertyInfo IsNot Nothing Then
propertyInfo.SetValue(ctl, _
GetEmptyValue( _
Utilities.GetPropertyType(propertyInfo.PropertyType)), _
New Object() {})
End If
I have basically put in a temporary fix as follows: -
If propertyInfo IsNot Nothing Then
If TypeOf (ctl) Is ComboBox Then
propertyInfo.SetValue(ctl,
String.Empty, New Object() {})
Else
propertyInfo.SetValue(ctl, _
GetEmptyValue( _
Utilities.GetPropertyType(propertyInfo.PropertyType)), _
New Object() {})
End If
End If
This gets me around the issue but maybe not in the neatest way possible. Incidentallly I tried the original code using Infragistics ultra combo box which allows null values and it worked just fine.