Skip to main content
 首页 » 编程设计

python之更新 Azure 服务计划后 Flask 应用程序失败

2025年02月15日10shangdawei

我有一个在 Azure 上运行的 Flask 应用程序。在我将 Azure 服务计划从“D1 共享”更新为“S1 标准”之前,它一直运行良好。

尝试访问应用程序时,出现以下错误:

Server Error in '/' Application.

Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

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.Configuration.ConfigurationErrorsException: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

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:

[ConfigurationErrorsException: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.]
System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) +6967379
System.Diagnostics.TypedElement.BaseGetRuntimeObject() +45
System.Diagnostics.ListenerElement.GetRuntimeObject() +83
System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() +142 System.Diagnostics.TraceInternal.get_Listeners() +185
System.Diagnostics.TraceInternal.WriteLine(String message) +119
System.Diagnostics.Debug.WriteLine(String message) +9
Microsoft.Web.Compilation.Snapshots.SnapshotHelper.RestoreSnapshot(String options) +359

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +160
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +2026
System.Web.Compilation.BuildManager.RestorePortableCompilationOutputSnapshot() +10008589 System.Web.Compilation.BuildManager.ExecutePreAppStart() +18 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

我尝试将服务计划更改回“D1 共享”,然后应用程序再次运行良好。

我看到很多帖子都说要确保解决方案引用了“Microsoft.Azure.Plugins.Diagnostics.dll”。我试图通过“右键单击”->“引用”->“添加引用...”->“.NET”->“Microsoft.Azure.Plugins.Diagnostics”来做到这一点。当我再次发布时,我可以在“bin”文件夹中看到 dll。但我仍然遇到同样的错误。

我是否以错误的方式进行引用?如果是这样,我该如何正确操作。

我还应该做些什么来使我的解决方案适用于“S1 标准”吗?

请您参考如下方法:

这是解决方案:

通过转到 Azure 门户 -> 应用程序设置 禁用动态缓存,然后将 'WEBSITE_DYNAMIC_CACHE' 的值设置为“0”(零)。

完成这些步骤后,尝试将您的定价层从共享扩展到标准。