I've got a big project that I'm just getting around to testing for the first time in Release mode, and I've found a big problem. This code finds all objects that are in the currently visible list but not in the database, and adds them to another list for later removal. Normally, if there are no differences, toRemove
remains empty. But in Release mode, toRemove
becomes populated with the entire visibleList
when there are no differences.
// Find which elements are in the visible list that do not exist in the database
foreach(var tr in visibleList.Where((entry) =>
{
return fullList.Contains(entry);
}))
{
toRemove.Add(tr);
}
After tearing apart the code and running some tests, I narrowed the problem down to this:
// Returns true in DEBUG mode, but false in RELEASE mode
// (when entry does in fact equal fullList[0])
bool equalityResult = entry.Equals(fullList[0]);
fullList
and toRemove
are just basic C# List<Entry>
objects, and visibleList
is an ObservableCollection<Entry>
.
Entry.Equals
is not overloaded.
Why would this function behave differently between the two configurations? What can I do to fix this?
EDIT: The bulk of the Entry
definition is:
public class Entry : INotifyPropertyChanged
{
public String Name { get; set; }
public String Machine { get; set; }
public Int32 Value { get; set; }
// Output values separated by a tab.
public override string ToString()
{
return String.Format("{0}\t{1}\t{2}", Name, Machine, Value);
}
public String ToCSVString()
{
return String.Format("{0},{1},{2}", Name, Machine, Value);
}
#region WPF Functionality
// Enable one-way binding in WPF
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string name)
{
PropertyChangedEventHandler h = PropertyChanged;
if (h != null)
{
h(this, new PropertyChangedEventArgs(name));
}
}
#endregion
// ...
}
EDIT: I implemented Entry.Equals
, and that fixed the problem. Turns out I had some linking errors on top of everything that caused the Entry.Equals
change in my code to be excluded from release builds. Having fixed that, and having implemented Equals
, everything works like a charm. It makes me sad that I have to override that method though, seems like a bit too much work.