locked
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. RRS feed

  • Question

  • User623455698 posted

    I'm trying to access local storage in azure and get the above exception when running the code:

    Dim myReportsStorage As LocalResource = RoleEnvironment.GetLocalResource("myReports")

    I've set up a cloud service. I can see that running in the portal and can connect to the instance and see the "myReports" folder through the remote desktop. I intially had a different problem "External component has thrown an exception." which I think was caused by my not giving the same name to the instance as I had to my website. Could this also be a naming problem?

    I'm trying to run some very simple code in my page load event. This works fine on my development machine but not in azure:        

    Dim myReportsStorage As LocalResource = RoleEnvironment.GetLocalResource("myReports")

    Dim sRoot As String = myReportsStorage.RootPath

    Dim sFile As String = sRoot & "NewFile.txt"

    If File.Exists(sFile) Then

    File.Delete(sFile)

    End If

    Using sw As StreamWriter = New StreamWriter(sFile)

                    sw.Write("Hello local storage!")

    End Using

    Using sr As StreamReader = New StreamReader(sFile)

    Me.Label1.Text = sr.ReadLine     

    End Using

     

    Saturday, July 28, 2012 8:03 AM

Answers

All replies

  • User623455698 posted

    I've now sorted this. I needed to follow the instructions at:

    http://www.windowsazure.com/en-us/develop/net/tutorials/cloud-service-with-sql-database/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 29, 2012 12:28 PM
  • User-884211243 posted

    I've got the exact same error here in the local emulator is works great but online it doesn't. 

    The article that is used as the solution doesn't point to a solution.

    Suggestions?

     

    Tuesday, June 4, 2013 10:07 AM
  • User623455698 posted

    The link appears to have been redirected to a new article. The link I gave originally was to "cloud-service-with-sql-database'. However if you follow the link today it goes to 'multi-tier-application ...'

    It's a while since I posted this but, as I remember, the error I made was to set my site up as a website rather than as a cloud service. Once I'd changed it to a cloud service all worked fine. The original link was to an article which described how to set up a cloud service.

    Tuesday, June 4, 2013 10:57 AM
  • User-884211243 posted

    Hello,

    thanks for the answer, I'm currently already working in a cloud solution. Thus something else is going on.

    After some research it seems that the Microsoft.Identitymodel dll (copy local set to true) is missing. Although it is present on the local cloud instance. Some suggest to contact MSFT support other try to fix it with a startup task to install the dll everytime the instance is started.

    Tuesday, June 4, 2013 11:01 AM