Question

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;

Was it helpful?

Solution 2

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 :-)

OTHER TIPS

Have you added a reference to the Microsoft.WindowsAzure.ServiceRuntime assembly in your MVC project?

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.aspx

FYI, if you're using Visual Studio's Azure templates, references to the following namespaces are included by default, so it's not necessary to set Copy Local to true:

  • Microsoft.WindowsAzure.Diagnostics
  • Microsoft.WindowsAzure.ServiceRuntime
  • Microsoft.WindowsAzure.StorageClient

To make sure Visual Studio and the SDK is installed correctly, you should be able to do the following: Create a new MVC3 Azure project, add a using directive for the ServiceRuntime library in your Home controller, then add the following code in the Index action:

ViewBag.configValue = RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
return View();

Then, add the following Razor syntax in the View:

<p>@ViewBag.configValue;</p>

And you should get the following result in your browser:

UseDevelopmentStorage=true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top