I can't figure out why it doesn't work. Here's the remove routine:
/// <summary>
/// Remove given IEntity from the list.
/// </summary>
/// <param name="entityToRemove">Entity object to remove from list.</param>
public void Remove(IEntity entityToRemove)
{
int index = List.IndexOf(entityToRemove);
if(index >=0)
{
if(BeforeRemove!=null)
{
BeforeRemove(entityToRemove, new EventArgs());
}
List.Remove(entityToRemove);
_contentInOriginalOrder.Remove(entityToRemove);
if(_containingEntity!=null)
{
entityToRemove.UnsetRelatedEntity(_containingEntity, _containingEntityMappedField);
}
OnListChanged(index, ListChangedType.ItemDeleted);
// remove subscribtion to the changed event.
entityToRemove.EntityContentsChanged -= new EventHandler(EntityInListOnEntityContentsChanged);
}
}
nowhere in there, it can run into a null reference unexpected, only when you pass in null yourself (which you don't, as you said).
If I start a simple test:
[Test]
public void RemoveFromCollectionTest()
{
ProductCollection products = new ProductCollection();
products.Add(EntityCreator.CreateNewProduct(1));
products.Add(EntityCreator.CreateNewProduct(2));
products[0].TestRunId = _testRunID;
products[1].TestRunId = _testRunID;
Assert.IsTrue((products.SaveMulti() > 0));
ProductEntity toRemove = new ProductEntity(products[0].ProductId);
products.Remove(toRemove);
}
It works (this entity uses a GUID as pk, so I thought it would be similar to your situation).
I'll now mail you a debug build of the ormsupport classes. Could you please place both files in the .zip in the bin folder of your application and test again? This will then give a stack trace which should have line numbers