Today, after adding a control to a WinForm within a project, you cannot open it, throwing the following exception.
System.Reflection.TargetInvocationException:Exception have been thrown by the target of a invocation. ---> System.NullReferenceException:Object reference not set to a 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
After checking, the error code is: Designer.cs:line 2547. This code is automatically generated by VisualStudio and there is no reason to make an error.
Later, I was reminded by my colleague When I open the Testform.resx file, VisualStudio hints that there are duplicates, after my new control, I renamed the control (only the case of the first name), which caused the testform.resx to appear with different case names, and after purging the obsolete items, WinForm normal.
This should be a VisualStudio bug.
WinForm. Designer.cs in-code throw reflection exception