Skip to content

Correct AutoMocker.Use instance check to use reference equality - #503

Merged
Keboo merged 1 commit into
masterfrom
fixEquals
Aug 12, 2026
Merged

Correct AutoMocker.Use instance check to use reference equality#503
Keboo merged 1 commit into
masterfrom
fixEquals

Conversation

@Keboo

@Keboo Keboo commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

AutoMocker.Use previously used value equality (Equals) when checking if an object instance had already been registered. This led to an InvalidOperationException when distinct object instances that were value-equal (e.g., Uri objects or C# records with the same property values) were provided.

Fixes: #470

This change updates the check to use ReferenceEquals, ensuring that the exception is only thrown when the exact same object instance is added multiple times, not merely value-equal instances.

Fixes #470.

`AutoMocker.Use` previously used value equality (`Equals`) when checking if an object instance had already been registered. This led to an `InvalidOperationException` when distinct object instances that were value-equal (e.g., `Uri` objects or C# records with the same property values) were provided.

This change updates the check to use `ReferenceEquals`, ensuring that the exception is only thrown when the exact same object instance is added multiple times, not merely value-equal instances.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The service instance has already been added. You can safely remove this call to AutoMocker.Use after update

1 participant