1. 程式人生 > >WinForm的.Designer.cs代碼內拋反射異常

WinForm的.Designer.cs代碼內拋反射異常

應該 mem document cli boolean 大小 bili 項目 dha

今天在項目內一個Winform增加控件後,無法打開,拋如下異常。

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at CM.CTOS.VesselDocument.CovCodControl.InitializeComponent() in C:\Test\TestForm.Designer.cs:line 2547

at CM.CTOS.VesselDocument.CovCodControl..ctor() in C:\Test\TestForm.cs:line 153
at CM.CTOS.VesselDocument.CovCodForm.InitUserControl() in C:\Test\TestForm.cs:line 58
at CM.CTOS.VesselDocument.CovCodForm..ctor() in C:\Test\TestForm.cs:line 43
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at CM.CTOS.WinUIAdmin.MenuManager.SubMenuClick(Object sender, EventArgs e) in C:\Test\MenuManager.cs:line 267

經檢查,出錯代碼在..Designer.cs:line 2547。此代碼是VisualStudio自動生成的,沒理由出錯。

後來經同事提醒,打開TestForm.resx文件時,VisualStudio提示有重復,原來我新控件後,對控件重命名了(只改了名字的大小寫),這樣導致了TestForm.resx出現大小寫名稱不同的項,清除廢棄項後,WinForm正常。

這應該是VisualStudio的Bug.

WinForm的.Designer.cs代碼內拋反射異常