diegofrata / Generator.Equals

A source code generator for automatically implementing IEquatable<T> using only attributes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReferenceExceptions starting with v2.7.2

bastianeicher opened this issue · comments

I’ve been using your lib for a while in 0install-dotnet. Great project, thanks!

Starting with v2.7.2 up to and including v2.7.5 my builds targeting .NET Framework 4.7.2 (with <Nullable>annotations</Nullable>) are throwing exceptions for null values:

System.NullReferenceException with message "Object reference not set to an instance of an object."
   at Generator.Equals.DefaultEqualityComparer`1.ObjectEqualityComparer.GetHashCode(T obj)
   at System.HashCode.Add[T](T value, IEqualityComparer`1 comparer)
   at ZeroInstall.Model.Command.GetHashCode() in /_/src/Model/Generator.Equals/Generator.Equals.EqualsGenerator/ZeroInstall.Model.Command.Generator.Equals.g.cs:line 58

The same code targeting .NET 6.0 (with <Nullable>enable</Nullable>) still works fine.

Was this an unintentional change or do I need to change something in my usage of the lib?

Can you provide me with a quick repro? That's definitely not intentional.

I think there's a difference between how System.HashCode.Add behaves in .NET 6.0 and .NET 4.7.2. The latter does not check whether the instance is null before calling GetHashCode, which is a bug in itself. I was able to come up with a fix for it.

Fixed in 2.7.6. The new packages should be in NuGet in a moment. I will raise a task to add test runs for .NET 4.7.2, as we our test suite only runs for .NET 6 at the moment.

Awesome, thanks! :)

Just tried the new version and everything looks good.