今天在项目内一个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代码内抛反射异常