Missing partial modifier on declaration of type 'x' - cause by auto-generated code by designer

ⅰ亾dé卋堺 提交于 2019-12-05 02:45:35

You (accidentally) have set the "Custom Tool" property for "ErrSer.resx" file to "ResXFileCodeGenerator". So Visual Studio generates a redundant source file for that file.

To solve the problem, open Solution explorer, then in "FormFile" folder expand "ErrSer.cs" node. Right-click the "ErrSer.resx" file and select "Properties". In the properties window clear the value of "Custom Tool" property:

Clear the specified value then build the project.

Your problem is that you have one Form named ErrSer and one resource file named ErrSer with a custom tool set. There are only two conditions comes to my mind for this case to happen

  1. You have a form and you accidentally set Custom Tool property on that file, so even if you do not need it to be generated and a ErrSer.Designer.cs file is generated for your resources.

  2. You have a form and you have created a ResX with same name.

For the first case just remove Custom Tool property on ResX file and generated Designer file. For the second case, rename your ResX file.

looking at this article it seem that you could change the behavior of the generation of the code behind.

the code provided seem to be for vs 2005/2008 (last modification seem to be 2009)

maybe you can adapt it for 2010 or later

there seem to be an extension for 2012 based on this article here

@jhyap: You have two options..

  1. Mark the System Generated Class as Partial.

Reason: you have already created a partial class which is similar to the class that is generated by the system. however system doesnt know that you have created the class with the same name. by marking the system generated class with the key word partial. The compiler will merge the class that you have written with the system generated class and treat it as a single class.

Note : if you decide to mark the system generated class as Partial you have to modifiy the Access modifier to Public from Internal, or make your class as Internal. Because Access modifiers should match when using the partial class concepts.

  1. Change the name of the class that you have written.

Reason: if in case you want to make sure that the calss that you have written has nothing to do with the class that is generated by the System and you do not want to merge the members of the System generated class with yours. then this is the best solution.

One of the above mentioned steps will solve your problem for sure.

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