Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing two instances of '(dynamic)null' fails in MSTest 3.2.2+ #3145

Closed
martinsuchan opened this issue Jun 21, 2024 · 5 comments · Fixed by #3181
Closed

Comparing two instances of '(dynamic)null' fails in MSTest 3.2.2+ #3145

martinsuchan opened this issue Jun 21, 2024 · 5 comments · Fixed by #3181

Comments

@martinsuchan
Copy link

martinsuchan commented Jun 21, 2024

Consider this one-liner:
Assert.AreEqual<dynamic>((dynamic)null, (dynamic)null);

In MSTest 3.2.1 it passed as true
in MSTest 3.2.2+ it fails with:

Assert.AreEqual failed. Expected:<(null)>. Actual:<(null)>. 
   at CallSite.Target(Closure , CallSite , Type , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)

Expected behavior

I'm no expert on the CLR dynamic specifics, but comparing two instances of (dynamic)null should probably pass, so the behavior in MSTest 3.2.2+ is the wrong one?

Tested in a .NET 4.8 Test project in VS 17.10.3

@martinsuchan
Copy link
Author

Looks like the origin of that behavior is in #2382 ?

@Evangelink
Copy link
Member

Hi @martinsuchan,

Thanks for the bug report. I confirm that I can reproduce the error and that at runtime, it seems to be picking the newly added overload with IEquatable<T> as you are pointing out. I will post back some update when I find what we can do.

@Evangelink
Copy link
Member

Is your real use case with nulls or is it with some other dynamic and you used null as a simple repro?

@martinsuchan
Copy link
Author

One of our tests started failing after updating MSTest, we use two paths to retrieve some db resources and we are comparing that both retrieve null. I was able to fix it already by using strong type instead of dynamic.

@Evangelink
Copy link
Member

We still have an invalid case for the IEquatable overloads when both are null, it should be considered as passing. Fixing this case is also fixing the one mentioned here.

Thanks @martinsuchan

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

Successfully merging a pull request may close this issue.

2 participants