Skip to content

Exception when comparing root elements #8

Closed
@Starkie

Description

@Starkie
Contributor

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);

Activity

Starkie

Starkie commented on Aug 8, 2018

@Starkie
ContributorAuthor

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.

pwelter34

pwelter34 commented on Feb 19, 2025

@pwelter34
Member

This is fixed in v6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pwelter34@Starkie

        Issue actions

          Exception when comparing root elements · Issue #8 · loresoft/EntityChange