dotnet/winforms

Icon.Save(stream) each time returns different results

Open

#8,853 创建于 2021年12月2日

在 GitHub 查看
 (13 评论) (0 反应) (0 负责人)C# (922 fork)batch import
area-System.Drawinghelp wanted

仓库指标

Star
 (4,100 star)
PR 合并指标
 (平均合并 14天 22小时) (30 天内合并 56 个 PR)

描述

Description

We use the following code to compare two icons:

private static bool IconEquals(Icon icon1, Icon icon2) {
                var stream1 = new System.IO.MemoryStream();
                icon1.Save(stream1);
                var stream2 = new System.IO.MemoryStream();
                icon2.Save(stream2);
                return System.Linq.Enumerable.SequenceEqual(stream1.ToArray(), stream2.ToArray());
        }

With the net6.0 release the stream.ToArray() method each time returns different results for the same Icon. You can modify the IconEquals as follows and it will return false:

private static bool IconEquals(Icon icon1) {
                var stream1 = new System.IO.MemoryStream();
                icon1.Save(stream1);
                var stream2 = new System.IO.MemoryStream();
                icon1.Save(stream2);
                return System.Linq.Enumerable.SequenceEqual(stream1.ToArray(), stream2.ToArray());
        }

Reproduction Steps

Launch the following code with any Icon:

private static bool IconEquals(Icon icon1) {
                var stream1 = new System.IO.MemoryStream();
                icon1.Save(stream1);
                var stream2 = new System.IO.MemoryStream();
                icon1.Save(stream2);
                return System.Linq.Enumerable.SequenceEqual(stream1.ToArray(), stream2.ToArray());
        }

Expected behavior

The IconEquals method should return true.

Actual behavior

The IconEquals method returns false.

Regression?

Works on net5.0

Known Workarounds

No response

Configuration

Windows 10

Other information

No response

贡献者指南