azureazure-role-environment

Cant read configuration. RoleEnvironment may be inaccessible due to its protection level


This is my first azure project and I'm not sure if I'm doing something wrong. I'm trying to get some configuration inside an MVC 3 webrole and for this I'm using:

RoleEnvironment.GetConfigurationSettingValue(KeyName)

When I run the application on the emulator i get his error:

BC30451: 'RoleEnvironment' is not declared. It may be inaccessible due to its protection level.

I tried to add the full namespace like this:

Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(KeyName)

And I get this error:

BC30456: 'ServiceRuntime' is not a member of 'WindowsAzure'.

However, I can access the RoleEnvironment inside the "OnStart" event of the WebRole class. So, is it the expected behavior? If yes, how am I supposed to read configuration through the whole project?

Thanks in advance;


Solution

  • I started a new solution based on seanost suggestion and it worked well, so I figured the problem wasn't VS. After a few try and errors I finally found a solution, I just don't have an explanation for it :-)

    Under my MVC project I have a folder called "App_Code". Since i come from web forms development I'm use to the name so I created this folder to keep some classes. If I try to access "RoleEnviroment" from a class inside this folder the project compiles but won't even open, no matter what I try to access it will throw the same error.

    If I rename the folder or move the files to another folder (let's say "Code"), it just works. As I said before, I just don't know why it happens (and it doesn;t really matter now :-)