Skip to content

ToolboxItemContainer.GetHashCode is not coherent with Equals #4738

Open

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

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
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions