views:

260

answers:

2

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Environment.GetResourceString("test"); //compile-time error
        }
    }
}

The error is: 'System.Environment' does not contain a definition for 'GetResourceString'.

EDIT: OP has stated that he's using the Compact Framework, v3.5.

I dont get the picture, what's wrong with my code? Thanks!

+2  A: 

Environment.GetResourceString appears to be present, according to MSDN, only in version 2.0 of the Compact Framework. If the article is to be believed, it's never existed in the standard framework.

What are you trying to do? If it's localization you're after, you may want ResourceManager.GetString.

System.Resources.ResourceManager myManager = new 
   System.Resources.ResourceManager("ResourceNamespace.myResources", 
   myAssembly);

// Retrieves String and Image resources.
string myString = myManager.GetString("StringResource");
Michael Petrotta
So is it Compact Framework only? (I'm targeting .NET 3.5) Yes it would be for localization. How come some class in the BCL are using this method (according to Reflector)?
Stringer Bell
Are you trying to use this method after observing that some of the BCL internals use it? I wouldn't recommend that. My guess is, the method is marked `internal`, and possibly is marked with `InternalsVisibleTo`, to allow use from within the BCL, but not outside it.
Michael Petrotta
The ResourceManager is supported in the CF, and its use would be the correct approach.
Michael Petrotta
Ok, I see, thanks a lot.
Stringer Bell
+1  A: 

Environment.GetResourceString is not public

internal static string GetResourceString(string key);

See Michael Petrottas answer for how to access resources or have a look at the samples here http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.aspx

Simon