【问题标题】:Not running in a hosted service or the Development Fabric (Production, not debug/local)不在托管服务或开发结构中运行(生产,非调试/本地)
【发布时间】:2012-12-14 13:17:37
【问题描述】:

我刚刚开始使用 Windows Azure,并且有一个使用 Azure 模拟器在本地运行的小型 MVC 应用程序。我注册了免费试用版,下载了我的发布配置文件并将其导入 VS2012。发布到 Azure 并得到一些程序集引用错误。我通过将它们设置为复制 local = true 解决了这个问题,现在我得到了:

    Not running in a hosted service or the Development Fabric. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Not running in a hosted service or the Development Fabric.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: Not running in a hosted service or the Development Fabric.]
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.GetDefaultStartupInfoForCurrentRoleInstance() +447
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener..ctor() +40

[ConfigurationErrorsException: Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.]
   System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) +6792949
   System.Diagnostics.TypedElement.BaseGetRuntimeObject() +45
   System.Diagnostics.ListenerElement.GetRuntimeObject() +83
   System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() +143
   System.Diagnostics.TraceInternal.get_Listeners() +181
   System.Diagnostics.TraceInternal.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args) +155
   DotNetOpenAuth.Loggers.TraceLogger.Info(Object message) +26
   DotNetOpenAuth.Logger.CreateWithBanner(String name) +45
   DotNetOpenAuth.Logger..cctor() +14

[TypeInitializationException: The type initializer for 'DotNetOpenAuth.Logger' threw an exception.]
   DotNetOpenAuth.Logger.get_Library() +14
   DotNetOpenAuth.Reporting.Initialize() +410
   DotNetOpenAuth.Reporting.set_Enabled(Boolean value) +31
   DotNetOpenAuth.Reporting..cctor() +285

[TypeInitializationException: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.]
   Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +41

[InvalidOperationException: The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254



--------------------------------------------------------------------------------

如果您在本地测试并且已将 Web 项目设置为启动项目而不是云项目时看到此错误,但正如我所说,这在本地对模拟器运行良好,但部署到 Azure 会导致失败。

任何想法我在这里缺少什么?

谢谢

【问题讨论】:

  • 你部署哪个项目?云项目(到云服务)还是 Web 应用程序(到 Windows Azure 网站)?
  • 我会追踪 DotNetOpenAuth 的依赖关系,并确保它们都是本地的。

标签: azure asp.net-mvc-4 dotnetopenauth


【解决方案1】:

尝试删除web.config 中的Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener 跟踪侦听器配置。请参阅此related SO postDotNetOpenAuth.Logger 似乎与 WAD 冲突(windows azure diagnostics)。

web.config中移除跟踪监听器:

<trace> 
    <listeners> 
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> 
            <filter type="" /> 
        </add> 
    </listeners> 
</trace>

【讨论】:

  • 这也可能会破坏单元测试,导致以下错误:调用执行程序“executor://mstestadapter/v1”时发生异常:对象引用未设置为对象的实例。或通过 mstest.exe:单元测试适配器抛出异常:无法创建 Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener、Microsoft.WindowsAzure.Diagnostics、Version=1.8.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35。不在托管服务或 Development Fabric 中运行..
  • 是的也有这个问题,这成功了。谢谢。
  • 只是提醒关注此答案的人 -> 这具有禁用整个项目的 Azure 诊断跟踪侦听器的副作用(这可能不是您正在寻找的解决方案)。
【解决方案2】:

将 Windows Azure 角色项目设置为“启动”项目。这解决了我的问题。当我在与启动项目相同的解决方案中设置另一个 webapp 时,我遇到了同样的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 1970-01-01
    相关资源
    最近更新 更多