升级后Post.Cast <>不再起作用

时间:2020-04-15 12:24:54

标签: c# inotifypropertychanged postsharp

我有以下代码(属于课程的一部分),多年来没有更改。我最近已从.net 4.5移至.net 4.7,并已从PostSharp 2升级到Postsharp 5.0.34。以下代码不再执行且出错。我已经将头撞在墙上几天了,但看不到为什么这将不再起作用?谁能对此有所启示?

//代码段

[NotifyPropertyChanged]
[Serializable]
[DataContract]
public class VimConnectionInfo : ConnectionInfoBase
{
    private const int HttpsPort = 443;

    public VimConnectionInfo()
    {
        this.SetDefaultValues();

        Post.Cast<VimConnectionInfo, INotifyPropertyChanged>(this).PropertyChanged += this.HandlePropertyChanged;
    }

从上面的代码段中,执行Post.Cast行时发生错误。由于该错误,未执行HandlePropertyChanged方法。错误消息如下

异常消息:无法将类型为'Advantage.Reporter.VCenter.Infrastructure.Connection.VimConnectionInfo'的对象转换为类型为'System.ComponentModel.INotifyPropertyChanged'。

来源: PostSharp

StackTrace:,位于PostSharp.Post.Cast [SourceType,TargetType](SourceType o) 在S:\ VisualStudioProjects \ Sonar.Portable \ Advantage.Reporter.VCenter \ Infrastructure \ Connection \ VimConnectionInfo.cs:第33行的Advantage.Reporter.VCenter.Infrastructure.Connection.VimConnectionInfo..ctor()中 在S:\ VisualStudioProjects \ Sonar.Portable \ Advantage.Reporter.VCenter \ Infrastructure \ Connection \ VimConnectionAdapter.cs:line 114中的Advantage.Reporter.VCenter.Infrastructure.Connection.VimConnectionAdapter.CreateConnectionInfo()处 在Advantage.Reporter.Core.Connections.ViewModels.ConnectionCollection。<> c__DisplayClass2_0。<。ctor> b__0(Object sender,AddingNewEventArgs e)中的S:\ VisualStudioProjects \ Sonar.Portable \ Advantage.Reporter.Core.Wpf \ Connections \ ViewModels \ ConnectionCollection.cs:第38行 在System.ComponentModel.AddingNewEventHandler.Invoke处(对象发送者,AddingNewEventArgs e) 在System.ComponentModel.BindingList 1.OnAddingNew(AddingNewEventArgs e) at System.ComponentModel.BindingList 1.FireAddingNew() 在System.ComponentModel.BindingList 1.AddNewCore() at System.ComponentModel.BindingList处1.System.ComponentModel.IBindingList.AddNew() 在DevExpress.Data.Helpers.BaseDataControllerHelper.AddNewRow() 在DevExpress.Data.BaseGridControllerEx.AddNewRow()

0 个答案:

没有答案