locked
RoleEnvironment issues in .NET backend for Azure Mobile Service RRS feed

  • Question

  • User-1812164866 posted

    Hello All. I have an Azure Mobile Service using the new .NET Backend for it. In Global.asax (application initialization), I am trying to call Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable to see if it is currently running in the cloud or not.

    So far, I have had nothing but issues with it.

    With just a reference to Microsoft.WindowsAzure.ServiceRuntime, I get a TypeInitializationException due to a lack of reference (or failure to load) msshrtmi.

    If I add a manual reference to msshrtmi one of two things happens:

    If it's the x86 reference, it works just fine but throws warnings when deploying. It runs fine and doesn't crash when accessing RoleEnvironment, but RoleEnvironment.IsAvailable always returns  false.

    If it's the x64 reference, it throws the same exception as if it were not there.

    I have cleaned (and deleted bin/obj) before deploying, deployed via the could service or publishing directly from the project, and have ensured that they are all set to Copy Local = True. Nothing seems to help.

    So, I need help with one of two things (from what I've been able to tell).

    1) A way to determine if the Mobile Service is currently running in the cloud (or cloud emulator) without using RoleEnvironment.

    2) A way to get msshrtmi working for my Mobile Service.

    One last note: as reference here, I have indeed made sure that they are all referencing the same copy of either x64 or x86 Windows.Azure.ServiceRuntime and msshrtmi.

    As a last last thought, I wonder if the Microsoft Azure Mobile Service is not running in a Role, even if it is set as a Web Role. If so, I will need a RoleEnvironment alternative.

    Help me on this!

    Thanks
    James mason

    Thursday, December 28, 2017 9:54 AM

All replies

  • User61956409 posted

    Hi James,<o:p></o:p>

    reference to Microsoft.WindowsAzure.ServiceRuntime, I get a TypeInitializationException due to a lack of reference (or failure to load) msshrtmi.

    As you did, RoleEnvironment.IsAvailable can help us detect if the role instance is running in the Windows Azure environment. If you get the “msshrtmi” loading related error, you can refer to this SO thread. Besides, if you want a RoleEnvironment alternative, you can add a setting to your config file and check if the setting exists with a specific value to see where your role instance is running.<o:p></o:p>

    With Regards, <o:p></o:p>

    Fei Han<o:p></o:p>

    Friday, December 29, 2017 2:40 AM