Hi!
I have generated wsdl, with (little bit strange) structure that contains value wrappers for simple types. StringValue for string, IntValue for int, that contains a property with such type.
For better use in my code, I extended all such values and overridden Equals, GetHashCode, ToString methods to work with inner value. So StringValue with Value = "some string" will return true for Equal on the same string.
The problem is: while serializing argument for a log, there are HashSet used for checking items, already added to the collection. In my case, when StringValue added, it is persisted in a hashset, and when it take Value of it, it's not added, because it Equals returns true, because Equals is overridden.
The proposed solution is to add configuration, that can be called like "useReferenceEqualsComparasion" to json logging section:
<attribute name="properties" encode="false">
<layout xsi:type='JsonLayout' includeAllProperties="true" includeMdc="true" renderEmptyObject="true" maxRecursionLimit="4" />
</attribute>
That will instructs to use custom EqualityComparer for this hashset (in class SingleItemOptimizedHashSet) that will call ReferenceEquals not a Equals for items comparsion.
@NoofSaeidh The idea is that it should check references. So I think it would be a non-breaking change to make it into always using references (And not using object.Equals). No extra setting is required.
does #2983 fix this issue?
@304NotModified does #2983 fix this issue?
Yes
@NoofSaeidh NLog ver. 4.5.11 has been released that fixes the issue: https://www.nuget.org/packages/NLog/
Most helpful comment
@NoofSaeidh NLog ver. 4.5.11 has been released that fixes the issue: https://www.nuget.org/packages/NLog/