9

The full error description is as per below:

enter image description here

And I found a few similar question posted before: A and B

But the question in A and B does not provide detail of problem description (perhaps we prompted the same error message but caused by different reason? I am not sure..). Any how, answer in A and B does not have good solution. So I decided to post the similar question with some more details.

My problem is as per below:

The Designer auto generate a new code (ErrSer1.Designer) which contain the same partial class name in (ErrSer.Designer). [Shown in printScreen_1 -> line 25 ]

The difference as we can see is, one is in ErrSer1.Designer (the extra auto generated one)

internal class ErrSer

Another one is in ErrSer.Designer (the original one who suppose to be)

partial class ErrSer

Here is the printScreen_1 to show ErrSer1.Designer (the extra auto-generated one) [ Notice line 25 ]

enter image description here

And here is the printScreen_2 to show ErrSer.Designer (the original and usual one) [ Notice line 3 ]

enter image description here

Lastly... what can I do to solve this annoying auto-generated code problem?

EDIT1: My ErrSer Form declared like this

public partial class ErrSer : Form

EDIT2: My .csproj file

My .csproj file location

Community
  • 1
  • 1
jhyap
  • 3,779
  • 6
  • 27
  • 47
  • Does it rebuild it even if you don't open the designer for it? I.e., only open the code behind to alter it, never opening the actual designer? – Rob G Apr 02 '13 at 02:03
  • Well.. this most annoying thing is the re-occurrence is not pattern. So far, what I did is, I delete the whole text in the auto-generated ErrSer1.Designer and close it. Then when i re-compile, then it will become fine. I did the same way yesterday, but today when I open and compile it again, then the same message prompted. – jhyap Apr 02 '13 at 02:48
  • The designer will update it every time you open the actual designer engine, I think. – Rob G Apr 02 '13 at 03:29
  • Ok.. I think it really seems the designer problem when i run the code with designer open. So, the temp solution for those who has similar problem as me, close the designer tab, and run ur code. – jhyap Apr 02 '13 at 05:50
  • How is your actual form declared? (I.E When you "View Code" of the form. This class also needs to be public and partial and have the same class name) – wdavo Nov 15 '13 at 03:58
  • Yes. By right it should be partial, but the designer auto generate an inner class which caused the problem. – jhyap Nov 15 '13 at 04:02
  • That's the designer class? Can you show the declaration for the ErrSer class which inherits from Form – wdavo Nov 15 '13 at 04:09
  • Please post the contents of your .csproj file. It seems that you have resource file in your project with the same name. I'm sure that the problem can be solved by modifying the .csproj file. – Mohammad Dehghan Nov 21 '13 at 08:14
  • can you specific the content of .csproj file which you want me to show? – jhyap Nov 21 '13 at 08:30
  • @jhyap All the sections that contain something related to `ErrSerr`. – Mohammad Dehghan Nov 21 '13 at 08:39
  • I right click the .csproj file and open it using notepad++, I do not see any ErrSerr keywords. – jhyap Nov 21 '13 at 08:45
  • @jhyap Please post the whole file contents, or upload it somewhere so we can take a look at it. Don't worry. It doesn't contain any sensitive information. It just contains the project structure. – Mohammad Dehghan Nov 21 '13 at 08:54
  • I will check this tomorrow when I back to office. – jhyap Nov 21 '13 at 11:23
  • You lost 50 point without giving it to any of the people that spent their precious time to help you. It's a pity. – Mohammad Dehghan Nov 23 '13 at 04:54

4 Answers4

2

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:

Solution Explorer and Properties windows

Clear the specified value then build the project.

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
  • This should not be the root cause. Because we create a new project with ResXFileCodeGenerator set, nothing goes wrong. So far only this particular project with ResXFileCodeGeberator set is having the problem. Hence I would like to conclude that, this is a ResXFileCodeGenerator bug from VS2010. – jhyap Nov 22 '13 at 00:33
  • Do you mean you always set this property for all the forms? Manually? Non of your other forms have this property set on their resx file. This property is only set for this particular file. I am creating winforms applications for over a decade and never have seen this property set on the .resx files for the *forms*. This is property is automatically set for *project resource files* (not related to any form). – Mohammad Dehghan Nov 22 '13 at 10:08
  • 1
    Try this: Create a new Windows Forms Application. Open the Solution Explorer, expand Form1, select Form1.resx and set "Custom Tool" property for it to "ResXFileCodeGenerator". Now build the project. You'll get the exact same error message. So, this **is** the root cause. – Mohammad Dehghan Nov 22 '13 at 10:11
1

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.

Erdogan Kurtur
  • 3,630
  • 21
  • 39
0

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

Fredou
  • 19,848
  • 10
  • 58
  • 113
0

@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.

Venkatesh Ellur
  • 158
  • 1
  • 10