在我的Azure应用程序中,当我尝试连接到本地模拟器时,我收到错误。
我收到错误的代码行是:
CloudStorageAccount CSC = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue("connection"));
在CS Def
<ConfigurationSettings>
<Setting name="connection" />
</ConfigurationSettings>
在.cscfg
<Role name="WebRole1">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="connection" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
堆栈追踪:
at RdGetApplicationConfigurationSetting(UInt16* , UInt16** )
at RoleEnvironmentGetConfigurationSettingValueW(UInt16* pszName, UInt16* pszDest, UInt32 cchDest, UInt32* pcchRequiredDestSize)
at Microsoft.WindowsAzure.ServiceRuntime.Internal.InteropRoleManager.GetConfigurationSetting(String name, String& ret)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName)
at WebRole1._Default.Page_Load(Object sender, EventArgs e) in c:\users\gowdes\documents\visual studio 2010\Projects\WindowsAzureProject20\WebRole1\Default.aspx.cs:line 19
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
答案 0 :(得分:3)
这可能看起来过于简单......但请仔细检查默认应用程序确实是您的Cloud Application项目而不是ASP.NET / Web项目。如果没有“云”上下文,您肯定会得到SHException或类似的内容。
答案 1 :(得分:2)
@Jim O'Neil已经指出你需要运行Cloud项目作为你的启动项目来避免SEHException。我还在this SO answer中讨论了SEHException。
查看上面的评论,您说您的代码符合else
部分:
if (RoleEnvironment.IsAvailable)
这意味着角色环境(例如Windows Azure)不可用,您将无法执行:
CloudStorageAccount CSC = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue("connection"));
这很可能是因为Cloud项目不是启动项目。或者,可能没有启动模拟器(如果您不以管理员身份运行Visual Studio,则会发生这种情况。)