简体   繁体   中英

Visual Studio C# Winform Designer is creating strange code for control members?

Thanks for your time everyone.

I'm working with C# .Net 4.0 and Visual Studio 2010 Professional. I have a few buttons, a richtextbox, and a splitcontainer on the form. There isn't a whole lot of code, and it doesn't really do much at the moment. There are two projects in the solution: call them MyProject and MySupportProject. The form is located in the MyProject project.

Every once and a while when I try to run the program, I get two errors:

'MySupportProject.Properties.Resources' is inaccessible due to its protection level
'MySupportProject.Properties.Resources' does not contain a definition for String1'

So I go look at the designer, and for some reason it keeps filling in the following:

this.rtbStatus.Text = global::MySupportProject.Properties.Resources.String1;

And I have no idea why. I delete it or comment it out and it keeps generating that line. The RTB (RichTextBox) in the form has no text associated with it.

In the solution properties, MySupportProject is listed as a dependency of MyProject, but I can't for the life of me figure out what it is trying to do with this particular RichTextBox with that particular non-visible string. I looked into the resource in MySupportProject a little bit and found the definition:

    /// <summary>
    ///   Looks up a localized string similar to .
    /// </summary>
    internal static string String1 {
        get {
            return ResourceManager.GetString("String1", resourceCulture);
        }
    }

It looks like the above definition was generated by some tool, but I'm really not sure where it came from. Someone worked on this project before me, so they could have put it in, but I started the form from scratch and I'm not making the connection. Has anyone ever had a similar issue? If not, is there something else I should try to stop this annoying occasional build failure? Thanks for all your help!

I don't exactly know reason behind this, but you can just replace the line with this:

this.rtbStatus.Text = "";

or:

this.rtbStatus.Text = null;

Also, try delete that string resource of yours. If you can't then do this:

  1. Check if there are any other resources stored in the resource file.
  2. If yes, then copy all the other resources into a new resource file and delete the old file.
  3. If not, then just delete the old resource file (.resx) and create a new resource file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM