AutoMapper升級至4.1.1後專案無法編譯
早上升級專案 AutoMapper 套件到最新版(4.1.1)後,發現專案無法通過編譯,查看錯誤訊息,看來是 AutoMapper 4.1.1 的屬性有些改變。
Profile.ProfileName
錯吳訊息
'xxx.ProfileName': cannot override inherited member 'Profile.ProfileName' because it is not marked virtual, abstract, or override
很明顯,新版本改變了 ProfileName 的存取方式,查詢AutoMapper Releases沒查到什麼有用的資訊。
按下F12查詢 Profile 類別的定義:
ProfileName
屬性僅能 get
,再看看建構式,解法很明顯了:
01 | public AtoB() |
02 | : base ( "xxx" ) |
03 | { } |
04 |
05 | //public override string ProfileName |
06 | //{ |
07 | // get |
08 | // { |
09 | // return "xxx"; |
10 | // } |
11 | //} |
將原本覆寫 ProfileName
屬性改成由 base()
傳遞給父類別。小怪一隻,打完結案。
感謝 Bruce 大大的分享
回覆刪除說明書沒寫只能跳坑硬扛XDD
回覆刪除錯,有 Source Code 自己看 XD
刪除在 4.2.1版, 這個問題似乎沒了..
回覆刪除看了一下Source Code:
public virtual string ProfileName { get; }
加入了 virtual ...