Print Page | Close Window

Intended behaviour?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2158
Printed Date: 29-Jul-2026 at 7:10am


Topic: Intended behaviour?
Posted By: jsobell
Subject: Intended behaviour?
Date Posted: 14-Sep-2010 at 9:24pm
Just struck an intersting error message in a moderately simple binding situation:

I have a selected node from a tree that has an optional 'Target' entity as a property.
Targets may or may not exist for a node, and the display switches between showing the target data and hiding it through a behaviour.
Given that the visibility is programmatic, the bindings are obviously always there (but the text boxes hide and display), so the XAML for the enclosed textbox is:

Text="{Binding SelectedNode.NodeTarget.TARGET, Mode=TwoWay}"

When the code runs, we get the error
"Null or pending entities cannot be modified"
from the Get of the
   public NodeTarget NodeTarget {
      get { return PropertyMetadata.NodeTarget.GetValue(this); }
<==== Here
      set { PropertyMetadata.NodeTarget.SetValue(this, value); }
    }

In this case 'this' is set to a valid entity, and this.NodeTarget is reported as '{NodeTarget:0} - Detached entity'

Setting Mode=OneWay has the same problem, so is this really intended behaviour? Why is a call to fetch a property from a non-initialised entity raising this particular exception?
I understand that it doesn't make sense to read a property from what is effectively a NULL reference, but this is one of the issues with XAML binding.

Any suggestions?

Cheers,
 Jason



Replies:
Posted By: jsobell
Date Posted: 14-Sep-2010 at 9:38pm
Interestingly, calling the Get on this property in code does not generate this exception, but any binding to it does, and yet according to VS2010 the Set method is never called.
What circumstances might cause this exception to be thrown via the Get method? Why is databinding so damned difficult to debug in VS?


Posted By: jsobell
Date Posted: 15-Sep-2010 at 11:57pm
Sorry, should have posted the following exception text too.

IdeaBlade.Core.IdeaBladeException occurred
  Message=Null or pending entities cannot be modified
  StackTrace:
       at IdeaBlade.EntityModel.EntityGroup.OnEntityPropertyChanging(EntityPropertyChangingEventArgs e)
       at IdeaBlade.EntityModel.EntityWrapper.SetValueWithChangeNotification(DataEntityProperty property, Object newValue)
       at IdeaBlade.EntityModel.EntityWrapper.SetValue(DataEntityProperty targetProperty, EntityWrapper sourceEntity, DataEntityProperty sourceProperty)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.UpdateOtherProperties(EntityRelationLink relationLink, EntityWrapper fromEntity, EntityWrapper toEntity)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.UpdateFkForNewToEntity(EntityWrapper toEntity)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.SetEntity(T newValue, Boolean updateFkValues, Boolean updateInverseValues)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.CreateOrFindPendingEntity(EntityReferenceStrategy strategy)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.QueryForEntity(EntityReferenceStrategy strategy)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.GetEntity(EntityReferenceStrategy strategy)
       at IdeaBlade.EntityModel.ScalarEntityReference`1.GetValue()
       at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.<.ctor>b__0(NavigationEntityPropertyGetInterceptorArgs`2 args)
       at IdeaBlade.Core.PropertyInterceptor`3.HandleAction(Action`1 action, TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.<BuildTargetedCombinedAction>b__3(TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.ExecuteActions(TArgs args)
       at IdeaBlade.Core.PropertyInterceptor`3.GetValue(TInstance instance, Object context)
       at IdeaBlade.Core.PropertyInterceptor`3.GetValue(TInstance instance)
       at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.GetValue(TInstance instance)
       at RiskStructureEditor.Web.Node.get_NodeTarget()
  InnerException:



Posted By: ting
Date Posted: 16-Sep-2010 at 6:40pm
Yes, we've seen the same artifiacts in binding where it is calling the 'set' even though it is only displaying and not modifying the value.  I know you've been chatting with Ward - you might want to bounce this one off him.


Posted By: cjohnson84
Date Posted: 19-Oct-2010 at 8:32am
Was this issue ever resolved?  I am now running into the "Null or pending entities cannot be modified" error.  In my particular case I have bound an Employee entity to my UI.  The Employee entity may or may not have a related Demographic entity.  If the Employee entity does not have a related Demographic entity when I examine the contents of my EntityManager I see a "detached" Demographic entity related to the Employee entity.  If I try to set a field in my UI (GenderID) that is in the Demographic entity I get the error.
 
Here is my stack trace:
 
   at IdeaBlade.EntityModel.EntityGroup.OnEntityPropertyChanging(EntityPropertyChangingEventArgs e)
   at IdeaBlade.EntityModel.EntityWrapper.SetValueWithChangeNotification(DataEntityProperty property, Object newValue)
   at IdeaBlade.EntityModel.EntityWrapper.IdeaBlade.EntityModel.IStructuralObject.SetValueWithChangeNotification(DataEntityProperty property, Object newValue)
   at IdeaBlade.EntityModel.DataEntityProperty`2.SetValueWithVerification(TInstance instance, TValue newValue)
   at IdeaBlade.EntityModel.DataEntityProperty`2.<.ctor>b__4(DataEntityPropertySetInterceptorArgs`2 args)
   at IdeaBlade.Core.PropertyInterceptor`3.HandleAction(Action`1 action, TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.<>c__DisplayClassb.<BuildTargetedCombinedAction>b__5(TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.ExecuteActions(TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.SetValue(TInstance instance, Object context, TValue value)
   at IdeaBlade.Core.PropertyInterceptor`3.SetValue(TInstance instance, TValue value)
   at IdeaBlade.EntityModel.DataEntityProperty`2.SetValue(TInstance instance, TValue value)
   at OrianaHouse.CMIS.Data.DataModel.Demographic.set_GenderID(Byte value)


Posted By: jsobell
Date Posted: 19-Oct-2010 at 3:46pm
Two very recent postings http://www.ideablade.com/forum/forum_posts.asp?TID=2222&title=1n-relation-does-not-validate - here and http://www.ideablade.com/forum/forum_posts.asp?TID=2234&title=invalidoperationexception-thrown-accessing-get-of-a-navigation-property - here also discuss the issue, but it's not going to be fixed until 6.0.7, so we'll have to wait.


Posted By: kimj
Date Posted: 19-Oct-2010 at 5:37pm
We did fix the problem in 6.0.6, so you won't have to wait long.  We'll post when 6.0.6 is up on the web site, but it should be real soon now.


Posted By: kimj
Date Posted: 19-Oct-2010 at 6:13pm

Version 6.0.6 is now available.




Print Page | Close Window