- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
"remove failed, remove returned false" exception when migrating to v2.0
Joined: 22-Mar-2006
I'm updating a WindowsForms app (Self Servicing using SQL Server 2005) from v1.0.2005.1 to v2.0 (Aug 3rd).
I'm getting a "The remove failed, as List<T>.Remove returned false" exception (exception and stack trace below).
My WindowsForm is data bound to a PaymentToCarrierEntity. PaymentToCarrier contains the Id of a BillFromCarrierEntity. BillFromCarrier is displayed as a dropdown list, and what is displayed in the list is a property I've defined on BillFromCarrier called DisplayName, defined like this:
public string DisplayName { get { string sDate = ""; if (BillDate != null) sDate = ((DateTime)BillDate).ToString("MM/dd/yy", null); // exception happens on the following line return Carrier.Name + ", " + CarrierAccount.AccountNum + sDate; } }
What appears to be causing the problem is that on this particular BillFromCarrier record, CarrierAccountId is null.
I tried to put in some checks as a workaround, but it seems that just trying to access any field of CarrierAccount causes the exception.
public string DisplayName { get { string sDate = ""; if (BillDate != null) sDate = ((DateTime)BillDate).ToString("MM/dd/yy", null); string sAccountNum = ""; int justTesting = 1; // now the exception happens on the following line. if (CarrierAccount != null && CarrierAccount.Id != 0) justTesting = 2; return Carrier.Name + ", " + sAccountNum + sDate; } }
Interestingly, if I run my v1.0.2005.1 app (that is, the same app before I converted it to 2.0) on this same database, it doesn't get an exception, and CarrierAccount.AccountNum is treated as a blank string.
I did a search for "remove failed" in this Forum, and only found one thread which was about a prefetchPath issue, which I don't think is the issue here.
I also saw the information in the "Migrating your code" section of the manual about how NULL database values now appear as null. But that doesn't seem to be the problem here.
Any assistance would be appreciated!
Thanks,
Wayne
System.ApplicationException occurred Message="The remove failed, as List<T>.Remove returned false" Source="SD.LLBLGen.Pro.ORMSupportClasses" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Remove(T item) in C:\ConfigureInc\BillTracker\LLBLGen2\ORMSupportClasses\CollectionCore.cs:line 424
SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore< DomainModel.EntityClasses.BillFromCarrierEntity>.Remove(DomainModel.EntityClasses.BillFromCarrierEntity item = {DomainModel.EntityClasses.BillFromCarrierEntity}) Line 427 C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase< DomainModel.EntityClasses.BillFromCarrierEntity>.SD.LLBLGen.Pro.ORMSupportClasses. IEntityCollection.Remove(SD.LLBLGen.Pro.ORMSupportClasses.IEntity entityToRemove = {DomainModel.EntityClasses.BillFromCarrierEntity}) Line 1516 + 0x9 bytes C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityBase. PerformRelatedEntityRemoval(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection collection = {DomainModel.CollectionClasses.BillFromCarrierCollection}, SD.LLBLGen.Pro.ORMSupportClasses.IEntity toRemove = {DomainModel.EntityClasses.BillFromCarrierEntity}, bool signalRelatedEntityManyToOne = true) Line 1770 + 0xb bytes C# DomainModel.dll!DomainModel.EntityClasses.CarrierAccountEntity.UnsetRelatedEntity( SD.LLBLGen.Pro.ORMSupportClasses.IEntity relatedEntity = {DomainModel.EntityClasses.BillFromCarrierEntity}, string fieldName = "BillFromCarrier", bool signalRelatedEntityManyToOne = true) Line 344 + 0x16 bytes C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityBase. PerformDesetupSyncRelatedEntity(SD.LLBLGen.Pro.ORMSupportClasses.IEntity relatedEntity = {DomainModel.EntityClasses.CarrierAccountEntity}, System.ComponentModel.PropertyChangedEventHandler propertiesChangedHandler = {System.ComponentModel.PropertyChangedEventHandler}, string fieldName = "CarrierAccount", SD.LLBLGen.Pro.ORMSupportClasses.IEntityRelation relation = {SD.LLBLGen.Pro.ORMSupportClasses.EntityRelation}, bool disconnectFromSaveEvent = true, bool signalRelatedEntity = true, string fieldInRelatedEntity = "BillFromCarrier", bool resetFKFields = true, int[] fkFieldIndexes = {Dimensions:[2]}) Line 2427 + 0xf bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.DesetupSyncCarrierAccount(bool signalRelatedEntity = true, bool resetFKFields = true) Line 1099 + 0x9d bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.SetupSyncCarrierAccount (SD.LLBLGen.Pro.ORMSupportClasses.IEntity relatedEntity = {DomainModel.EntityClasses.CarrierAccountEntity}) Line 1107 + 0xe bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.SetRelatedEntity( SD.LLBLGen.Pro.ORMSupportClasses.IEntity relatedEntity = {DomainModel.EntityClasses.CarrierAccountEntity}, string fieldName = "CarrierAccount") Line 310 + 0x9 bytes C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase< DomainModel.EntityClasses.BillFromCarrierEntity>.PerformSetRelatedEntity( DomainModel.EntityClasses.BillFromCarrierEntity entity = {DomainModel.EntityClasses.BillFromCarrierEntity}) Line 1080 + 0x13 bytes C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore< DomainModel.EntityClasses.BillFromCarrierEntity>.PerformAdd(DomainModel.EntityClasses.BillFromCarrierEntity item = {DomainModel.EntityClasses.BillFromCarrierEntity}) Line 1211 + 0xd bytes C# SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore< DomainModel.EntityClasses.BillFromCarrierEntity>.Add(DomainModel.EntityClasses.BillFromCarrierEntity item = {DomainModel.EntityClasses.BillFromCarrierEntity}) Line 312 + 0x9 bytes C# DomainModel.dll!DomainModel.EntityClasses.CarrierAccountEntity.SetRelatedEntity( SD.LLBLGen.Pro.ORMSupportClasses.IEntity relatedEntity = {DomainModel.EntityClasses.BillFromCarrierEntity}, string fieldName = "BillFromCarrier") Line 316 + 0x32 bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.CarrierAccount.set( DomainModel.EntityClasses.CarrierAccountEntity value = {DomainModel.EntityClasses.CarrierAccountEntity}) Line 1732 + 0x10 bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.GetSingleCarrierAccount(bool forceFetch = false) Line 751 + 0xd bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.CarrierAccount.get() Line 1714 + 0xd bytes C# DomainModel.dll!DomainModel.EntityClasses.BillFromCarrierEntity.DisplayName.get() Line 28 + 0x29 bytes C# [Native to Managed Transition] [Managed to Native Transition] System.dll!System.ComponentModel.ReflectPropertyDescriptor.GetValue(object component = {DomainModel.EntityClasses.BillFromCarrierEntity}) + 0x57 bytes System.Windows.Forms.dll!System.Windows.Forms.ListControl.FilterItemOnProperty(object item = {DomainModel.EntityClasses.BillFromCarrierEntity}, string field) + 0x61 bytes System.Windows.Forms.dll!System.Windows.Forms.ListControl.GetItemText(object item = {DomainModel.EntityClasses.BillFromCarrierEntity}) + 0x9f bytes System.Windows.Forms.dll!System.Windows.Forms.ComboBox.UpdateText() + 0x7a bytes System.Windows.Forms.dll!System.Windows.Forms.ComboBox.SelectedIndex.set(int value) + 0xd9 bytes System.Windows.Forms.dll!System.Windows.Forms.ListControl.SelectedValue.set(object value) + 0x72 bytes [Native to Managed Transition] [Managed to Native Transition] System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(object component = {System.Windows.Forms.ComboBox, Items.Count: 7}, object value = 26) + 0x11b bytes System.Windows.Forms.dll!System.Windows.Forms.Binding.SetPropValue(object value) + 0xc9 bytes System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData(bool force) + 0x71 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData(out bool success = true) + 0x50 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData() + 0xe bytes System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.CurrencyManager_PushData() + 0x5e bytes System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnCurrentChanged(System.EventArgs e = {System.EventArgs}) + 0x35 bytes System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordState(int newPosition, bool validating, bool endCurrentEdit, bool firePositionChange = true, bool pullData) + 0x11d bytes System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.Position.set(int value) + 0x3e bytes System.Windows.Forms.dll!System.Windows.Forms.BindingSource.MoveLast() + 0x27 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingNavigator.OnMoveLast(object sender, System.EventArgs e) + 0x24 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.RaiseEvent(object key, System.EventArgs e) + 0x41 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripButton.OnClick(System.EventArgs e) + 0x3e bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) + 0xc7 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp( System.Windows.Forms.MouseEventArgs e = {X = 8 Y = 7 Button = Left}) + 0x220 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEventInteractive(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x87 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x122 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) + 0xc7 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0xf2 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x544 bytes System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x45 bytes System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0x10ffc wparam=0x0 lparam=0x800b0 result=0x0}) + 0x71 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes [Native to Managed Transition] [Managed to Native Transition] System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2ea bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes DataEntry.exe!DataEntry2.Program.Main() Line 15 + 0x1a bytes C# [Native to Managed Transition] [Managed to Native Transition] mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x32 bytes Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio. HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes
Joined: 22-Mar-2006
Hi Walaa,
Thanks for your quick response. I tried your suggestion, but it didn't help, because when I add this new test the new test causes the same exception:
public string DisplayName {
get {
string sDate = "";
if (BillDate != null)
sDate = ((DateTime)BillDate).ToString("MM/dd/yy", null);
string sAccountNum = "";
// Exception on following line
if (this.CarrierAccount.Fields.State == EntityState.Fetched)
sAccountNum = this.CarrierAccount.AccountNum;
return Carrier.Name + ", " + sAccountNum + sDate;
}
}
But as I investigated this problem, I noticed something very odd: the exception happens after DisplayName is successfully displayed. The record with CarrierAccountId having a null value is the 3rd record to be displayed. So when I first display the form, it shows the 1st record correctly. I use the arrow icon in the Navigation bar to go to the 2nd record, then to the 3rd record. The 3rd record displays fully and correctly. In particular, the dropdown that shows the values of the above DisplayName property shows "name,", which is what I would expect. It's only after this record displays that the exception happens. It happens immediately after the record is displayed. (All this works the same with or without the change you suggested.)
In other words, the first time the DisplayName property is accessed for this record, it works fine. It's only some later call that causes an exception.
In the stack trace for the exception (which is basically the same as the stack trace I posted above), System.Windows.Forms.Control.Show() does not appear anywhere on the stack. Show() does appear in the "usual" case when the form is being displayed (which does not cause the exception).
(Something I didn't mention last time because I don't think it's important is that BillForCarrier is a sub-type of Bill).
Did something change in this area from v1.0.2005.1 to v2.0 because this all works fine on v1.0.2005.1.
Thanks,
Wayne
I think the stack trace contradicts with the place you said the exception would occur in code.
As the trace shows that the exception occurs when a remove of an entity from a collection of BillForCarrier happens.
I think this happens because of the bounded dropdown list. Which tries to select a value of null from its values to display the corresponding Name.
I think you should handle an event like "item_DataBound" and try to select the name manually fro the dropdown list, provided that you have a default name of "N/A" for example that you would select in these situations.
Joined: 22-Mar-2006
I think you should handle an event like "item_DataBound"
Thanks! I put in the following code, which seems to avoid the exception:
string sAccountNum = "";
if (this.CarrierAccountId != null)
sAccountNum = CarrierAccount.AccountNum;
I'd still appreciate your comments on what changed between v1.0.2005.1 and v2.0 to provoke this exception, so I'll know what similar situations to look for in my code to make sure the same exception doesn't occur there.
Thanks,
Wayne
Most probably because in the previous version default values dotNet DataTypes defaults, i.e for integers it was Zero rather than null.
Now in v.2 and with the dotNet nullable dataType an Integer property of no value might have a null value (you control whether to use nullable dataTypes or not).