EntityChange icon indicating copy to clipboard operation
EntityChange copied to clipboard

Exception when comparing root elements

Open Starkie opened this issue 7 years ago • 1 comments

This issue was detected when comparing root elements, for example, of a value type. When change is detected in the root element, a null reference exception is launched when creating the ChangeRecord (CreateChange() method):

var displayName = currentMember.DisplayName ?? propertyName.ToSpacedWords();

It seems to be caused by the currentMember variable, which is null when comparing root elements.

Code snippet to reproduce the error:

int original = 1;
int current  = 2;

var comparer = new EntityComparer();
var changes = comparer.Compare(original, current);

Starkie avatar Aug 07 '18 09:08 Starkie

With further testing, now comparing arrays as root nodes, I found another exception in the method CompareByIndexer<T>:

When peeking the pathStack, an InvalidOperationException is thrown because it is empty: var currentPath = _pathStack.peek().

Changing that line for var currentPath = CurrentPath() seems to solve the issue.

Edit: Apparently, I introduced this bug while fixing #5, and applying the proposed fix causes a regression. I'll try to look up for another solution.

Starkie avatar Aug 08 '18 08:08 Starkie