Windows forms designer NullReferenceException- where to go from here?

夙愿已清 提交于 2020-01-06 12:53:53

问题


When I try to open one of my forms in the designer, it says, "Object reference not set to an instance of an object." It does not provide a way to continue, and it does not give me any clue as to what is causing the error.

at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.System.CodeDom.Compiler.ICodeParser.Parse(TextReader stream)
at System.CodeDom.Compiler.CodeDomProvider.Parse(TextReader codeStream)
at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomDocDataAdapter.get_CompileUnit()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) 

The code compiles and runs perfectly. Cleaning, rebuilding, closing, reopening haven't worked. All the other forms open fine.

I don't even know what information is relevant. What recourse do I have to debug this?


回答1:


This will sound silly. The form is apparently a duplicate for a work in progress and the build action was set to None. Setting it to Compile caused the designer to act as normal.

It would be nice if the designer would at least point you in the right direction. Problem solved.




回答2:


This is because there is' an exception in the event "Load" of the form. Place the code inside a "try .. catch" block to see the exception



来源:https://stackoverflow.com/questions/23695733/windows-forms-designer-nullreferenceexception-where-to-go-from-here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!