gpt4 book ai didi

c# - WindowsBase.dll 中发生类型为 'System.InvalidCastException' 的第一次机会异常

转载 作者:太空狗 更新时间:2023-10-29 22:00:57 24 4
gpt4 key购买 nike

将 ListBox 的 ItemsSource 绑定(bind)到 ObservableCollection<object> 时出现此异常.

该集合混合了 {DependencyPropertyChangedEventArgs, EventEntry}

我偷看了DependencyPropertyChangedEventArgs并发现:

public struct DependencyPropertyChangedEventArgs
{
...
public override bool Equals(object obj)
{
return this.Equals((DependencyPropertyChangedEventArgs)obj); <- huge cast right here?
}
}

EventEntry 代码:

public class EventEntry
{
public EventEntry(string name)
{
Name = name;
}
public string Name { get; private set; }
}

当我阅读偷看的代码时,它会爆炸。

这样对吗?

最佳答案

确认错误,重现:

[Test]
public void Repro()
{
var args = new DependencyPropertyChangedEventArgs(UIElement.IsEnabledProperty, false, true);
Assert.Throws<InvalidCastException>(() => args.Equals(1));
}

Confirmed bug in the implementation: (below code is from reference source)

public override bool Equals(object obj)
{
return Equals((DependencyPropertyChangedEventArgs)obj);
}

Filed a bug on Connect

关于c# - WindowsBase.dll 中发生类型为 'System.InvalidCastException' 的第一次机会异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23585430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com