I have a scenario where I need to be able to use the Microsoft.WindowsAzure.ServiceRuntime
outside of a Web/Worker role.
Specifically I have the following code
public static RoleInstanceEndpoint ResolveIP()
{
if (RoleEnvironment.IsAvailable)
{
RoleInstance instance = RoleEnvironment.CurrentRoleInstance;
RoleInstance RelatedWCFInstance = RoleEnvironment.Roles["MyServiceRoleName"]
.Instances
.Where(o => o.UpdateDomain == instance.UpdateDomain)
.FirstOrDefault();
if (RelatedWCFInstance != null)
return RelatedWCFInstance.InstanceEndpoints.Where(o => o.Value.Protocol == "tcp").FirstOrDefault().Value;
}
return null;
}
This code successfully executes when running inside the RoleEntryPoint.OnStart
event but when I try to execute this code in a separate exe that is triggered via Azure startup tasks like this
<Startup>
<Task commandLine="StartupMagic.exe" taskType="simple" executionContext="elevated" />
</Startup>
I receive the following error
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.
Could someone please confirm if it is infact possible to reference this library outside of a Web or Worker role? and if so provide any advice on what I might be doing wrong?