dotnet / dotnet/winforms

ToolboxItemContainer.GetHashCode is not coherent with Equals

Open
#4,738 2 comments 0 reactions 1 assignee Claimed by @merriemcgaw View on GitHub
area-DesignerSupport
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

* .NET Core Version:
The latest .Net 6.0 SDK build

* Have you experienced this same bug with .NET Framework?:
Yes, currently released .NET Framework 4.8 (and earlier)

**Problem description:**
Run the following code
```cs
using System;
using System.Drawing.Design;

namespace ReproToolboxItemContainer
{
class Program
{
static void Main(string[] args)
{
var tbic1a = new ToolboxItemContainer(new ToolboxItem(typeof(string)));
var tbic2a = new ToolboxItemContainer(new ToolboxItem(typeof(string)));

var tbic1b = new ToolboxItemContainer(tbic1a.ToolboxData);
var tbic2b = new ToolboxItemContainer(tbic2a.ToolboxData);

Console.WriteLine(tbic1b.GetHashCode()); // Prints 273577200
Console.WriteLine(tbic2b.GetHashCode()); // Prints 324609509

// See https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/1286215/
Console.WriteLine(tbic1b.Equals(tbic2b)); // Prints 'False'
Console.WriteLine(tbic1b.Equals(tbic2b)); // Prints 'True'

Console.WriteLine(tbic1b.GetHashCode()); // Prints 273577200
Console.WriteLine(tbic2b.GetHashCode()); // Prints 324609509

Console.WriteLine(tbic1b.GetToolboxItem(null).GetHashCode()); // Prints 271327533
Console.WriteLine(tbic2b.GetToolboxItem(null).GetHashCode()); // Prints 271327533
}
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.