views:

352

answers:

1

When I try try to access a string property in one of my C# project resources, I get the following error:

'ORG.PRJ.MOD.MyClass2' does not contain a definition for 'Properties'

The code that produces the error is:

string s = MyClass2.Properties.Resources.TestString2;

The really bizarre thing is that another project in my solution (using MyClass and TestString) with exactly the same setup does NOT produce the error and works like a champ. Here is the background and all the things I have tried.

  1. Both are plain "Class Library C#" projects in VS2008.
  2. I created the resource strings via right-click->Properties for each project in the solution tree, then selecting the "Resources" tab. Then I just entered a "TestString" in one, and a "TestString2" in the other.
  3. For the project that works, if I type MyClass. - the IDE IntelliSense tells me that "Properties" is an available member (but that is the ONLY member it shows me). For the project that doesn't work, the available members are "Equals" and "ReferenceEquals" (it does NOT give me "Properties"). This seems to be the biggest clue that SOMETHING is different.
  4. Thinking my project files got corrupted, I completely created both projects again from scratch. I deleted all bin, obj, and Properties folders, deleted all Resources.resx and Resources.Designer.cs files, deleted all .csproj, .csproj.user, .sln, and .suo files. For BOTH projects. Then I started up VS2008 again and used File->New->"Project From Existing Code..." to create new projects. Then I added the resources in exactly the same way for both projects (per Step 2 above). Same results.
  5. I have performed a 'diff' on the corresponding files between the two projects (Resources.resx, Resources.Designer.cs, MyProj.csproj). Nothing looks different other than what I would expect (class names and string names differ between them).
  6. I've googled it to death. Based on how bizarre this feels, there's no doubt I've done something insanely stupid (see http://stackoverflow.com/questions/58640/great-programming-quotes/756768#756768).
+3  A: 

The Properties static class is accessible via the default namespace for your project. Now, given that it's a class library, that might be Class2 (or perhaps that there might be a naming clash, ie. by having a Class2.Class2), but something tells me that that is a class in your library, not the namespace (which would produce the error you describe).

Matthew Scharley
It was a default namespace issue. BOTH projects had the project name as their default namespaces when I recreated them from scratch. They should have both had 'ORG.PRJ.MOD'. I still don't understand why one compiled and the other didn't.
e-holder
Ahhh! For MyClass, the project name is different from the class name. For MyClass2, the project name and the class name are identical. THAT explains it. Thanks Matthew!
e-holder