<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Problem with event handlers on cloned entities</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Problem with event handlers on cloned entities</description>
  <pubDate>Tue, 12 May 2026 23:35:20 -700</pubDate>
  <lastBuildDate>Fri, 15 Mar 2013 17:18:13 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=3990</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Problem with event handlers on cloned entities : Great, thanks! </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16041#16041</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 15-Mar-2013 at 5:18pm<br /><br />Great, thanks!]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 17:18:13 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16041#16041</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities :   We plan to release it next...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16040#16040</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 15-Mar-2013 at 4:51pm<br /><br />We plan to release it next Tuesday, 3/19.]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 16:51:02 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16040#16040</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : Any update on when this release...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16039#16039</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 15-Mar-2013 at 4:09pm<br /><br />Any update on when this release will be available. &nbsp;We are eagerly awaiting the release and I'd say it is now technically mid-March :-).<div><br></div><div>Thanks,</div><div>-Stephen</div>]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 16:09:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=16039#16039</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : We&amp;#039;re planning a new release...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15913#15913</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 25-Feb-2013 at 4:49pm<br /><br />We're planning a new release mid-March.]]>
   </description>
   <pubDate>Mon, 25 Feb 2013 16:49:00 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15913#15913</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : Any estimate on when the next...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15911#15911</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 25-Feb-2013 at 3:21pm<br /><br />Any estimate on when the next release will be available? &nbsp;We are looking to upgrade soon.]]>
   </description>
   <pubDate>Mon, 25 Feb 2013 15:21:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15911#15911</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : That is great news. Thanks for...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15878#15878</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 20-Feb-2013 at 8:42am<br /><br />That is great news. &nbsp;Thanks for the update.]]>
   </description>
   <pubDate>Wed, 20 Feb 2013 08:42:30 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15878#15878</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : Hi stephenmcd1,  I wanted to let...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15873#15873</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 18-Feb-2013 at 1:48pm<br /><br />Hi stephenmcd1,<br /><br />I wanted to let you know that we have fixed these issues. <br />They will be available in the next release of DevForce 2010.<br /><br />sbelini]]>
   </description>
   <pubDate>Mon, 18 Feb 2013 13:48:48 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15873#15873</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : Hi stephenmcd1,  We are investigating...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15867#15867</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 15-Feb-2013 at 2:26pm<br /><br />Hi stephenmcd1,<br /><br />We are investigating these problems and will keep you informed.<br /><br />sbelini.<span style="font-size:10px"><br /><br />Edited by sbelini - 15-Feb-2013 at 2:26pm</span>]]>
   </description>
   <pubDate>Fri, 15 Feb 2013 14:26:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15867#15867</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : After doing some very ugly hacking...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15865#15865</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 13-Feb-2013 at 11:19am<br /><br />After doing some very ugly hacking in our code to try to work around the issue above, I've run into another problem with the Clone logic. &nbsp;And I don't think there will be any way I can work around this one. &nbsp;Luckily, it seems even more clearly a bug and probably even easier to fix than the issue above.<div><br></div><div>The problem happens when you clone an entity that already has validation errors. &nbsp;In that case, the Entity Aspect cloning logic will create a new collection to hold the errors - which is correct. &nbsp;But it passes the old entity aspect to the collection so things get a bit messed up. &nbsp;The relevant code is in EntityAspect.CloneCore() and looks like this:<table width="99%"><tr><td><pre class="BBcode"><span style="line-height: 1.4;">&nbsp; &nbsp; if (this._validationErrors != null)</span></div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; aspect._validationErrors = new VerifierErrorsCollection(this, this._validationErrors);</div><div>&nbsp; &nbsp; }</div><div></pre></td></tr></table></div><div><br></div><div>Note that is is giving 'aspect' (the new aspect) a new VerifierErrorsCollection. &nbsp;But it's passing 'this' (the source aspect) to the collection! &nbsp;So the new aspect is holding onto a collection and the collection thinks it is associated with the old aspect! &nbsp;It seems that this same kind of bug exists in other places in that method (the OriginalValuesMap and BackupValuesMap fields jump out).</div><div><br></div><div>Here is some test code to help explain things:<table width="99%"><tr><td><pre class="BBcode">&nbsp; &nbsp; &nbsp; &nbsp; public void CloneTests2()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make an entity with validation errors</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var firstEntity = new MyEntity();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstEntity.EntityAspect.ValidationErrors.Add(new VerifierResult(false));</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make a copy of the original entity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var secondEntity = (MyEntity)((ICloneable)firstEntity).Clone();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The validations errors will correctly get copied to the cloned entity.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(1, secondEntity.EntityAspect.ValidationErrors.Count);//Pass</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //But the VerifierErrorsCollection on the cloned entity isn't quite setup right. &nbsp;For example...</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //See if ErrorsChanged fires on the second entity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var errorChangeFiredOnSecondEntity = false;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((INotifyDataErrorInfo)secondEntity).ErrorsChanged += (_, __) =&gt; errorChangeFiredOnSecondEntity = true;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Clear out the errors on the second entity to see what happens</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secondEntity.EntityAspect.ValidationErrors.Clear();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The error was correctly removed</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(0, secondEntity.EntityAspect.ValidationErrors.Count);//Pass</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //However, this line will fail because ErrorsChanged was not raised on the second entity. &nbsp;In fact, it was raised on the&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;first entity - even though the errors on the first entity weren't touched.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.IsTrue(errorChangeFiredOnSecondEntity);//Fail</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Further support for the VerifierErrorsCollection being messed up....let's check out the _entityAspect field on the collection</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //On the first entity, the aspect is correct</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreSame(firstEntity.EntityAspect, GetAspect(firstEntity.EntityAspect.ValidationErrors));//Pass</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //However, these two lines will fail. &nbsp;We'd expect the aspect of the second collection to be the same as the second&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;entity's aspect...but it's not! &nbsp;And in fact, the aspect is still pointing to the first entity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreSame(secondEntity.EntityAspect, GetAspect(secondEntity.EntityAspect.ValidationErrors));//Fail</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreNotSame(firstEntity.EntityAspect, GetAspect(secondEntity.EntityAspect.ValidationErrors));//Fail</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; private EntityAspect GetAspect(EntityAspect.VerifierErrorsCollection collection)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Ugly code to get at the private field</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (EntityAspect)typeof(EntityAspect.VerifierErrorsCollection)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.GetField("_entityAspect", BindingFlags.Instance | BindingFlags.NonPublic)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.GetValue(collection);</div><div><span style="line-height: 1.4;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></pre></td></tr></table></div>]]>
   </description>
   <pubDate>Wed, 13 Feb 2013 11:19:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15865#15865</guid>
  </item> 
  <item>
   <title>Problem with event handlers on cloned entities : We&amp;#039;ve been playing around...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15864#15864</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3990<br /><strong>Posted:</strong> 13-Feb-2013 at 9:48am<br /><br />We've been playing around with different ways to quickly move entities from one Entity Manager to another (see <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=3978&amp;title=per&#102;ormance-issues-with-importentities" target="_blank">this </a>thread). &nbsp;We've tried using the Clone method but run into problems where event handlers that subscribed to the original entity get raised when changes are made to the newly cloned entity. &nbsp;It seems to be an issue with the way the EntityAspect is cloned - it starts with a MemberwiseClone which will end up giving the new aspect the same delegate used in the original aspect.<div><br></div><div>Here is some test code that might explain my problem more clearly:<table width="99%"><tr><td><pre class="BBcode">&nbsp; &nbsp; &nbsp; &nbsp; public void CloneTests()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var firstEntity = new MyEntity();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((INotifyDataErrorInfo)firstEntity).ErrorsChanged += (_, __) =&gt; Assert.Fail("ErrorsChanged fired on first entity");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstEntity.PropertyChanged += (_, __) =&gt; Assert.Fail("PropertyChanged fired on first entity");</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make a copy of the original entity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var secondEntity = (MyEntity)((ICloneable)firstEntity).Clone();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Either force property change or change the validation errors on this *second* entity. &nbsp;Both these lines will fail because</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;they will end up executing the code that subscribed to these events on the first entity!</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secondEntity.EntityAspect.ForcePropertyChanged(new PropertyChangedEventArgs("something"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secondEntity.EntityAspect.ValidationErrors.Add(new VerifierResult(false));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</pre></td></tr></table></div><div><br></div><div>I'm hoping this isn't just an unsupported scenario. &nbsp;Obviously, if I wait until after the clone to attach the event handlers, everything works as expected. &nbsp;But in our code, it's not always easy to do that. &nbsp;And I haven't found an easy way to work around this in our code (and the reflection restrictions in Silverlight do not help!).</div>]]>
   </description>
   <pubDate>Wed, 13 Feb 2013 09:48:48 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3990&amp;PID=15864#15864</guid>
  </item> 
 </channel>
</rss>