码迷,mamicode.com
首页 > Windows程序 > 详细

WinForm的.Designer.cs代码内抛反射异常

时间:2017-11-03 11:13:03      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:throw   component   imp   sig   slow   info   uri   designer   nta   

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

标签:throw   component   imp   sig   slow   info   uri   designer   nta   

原文地址:http://www.cnblogs.com/todayhero/p/7776754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!