簡體   English   中英

使用Visual Studio 2017進行調試時,“請求在此上下文中不可用”

[英]“Request is not available in this context” when debugging with Visual Studio 2017

我從Visual Studio 2015升級到Visual Studio2017。當將其部署到Azure App Services以及使用Visual Studio 2015對其進行調試時,將運行以下代碼。但是在Visual Studio 2017中進行調試時,它將引發異常:

在這種情況下請求不可用

對於VS2015和VS2017,IIS Express用於調試。 現在安裝了VS2017 IIS 10.0 Express(10.0.1737),我不記得VS2015使用哪個版本。

該代碼是基於ASP.NET 4.5.2 Azure API App模板的C#。 它注冊了一個接收器,用於從Azure Event Hub訂閱事件。

using System;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Configuration;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.EventHubs.Processor;
using Microsoft.ApplicationInsights;
using System.Collections.Generic;

namespace ....

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.EnableCors();
            // Web API routes
            config.MapHttpAttributeRoutes();

            try
            {
                Console.WriteLine("Registering EventProcessor...");

                ...

                var eventProcessorHost = new EventProcessorHost(
                        EhEntityPath,
                        EhConsumerGroup,
                        EhConnectionString,
                        StorageConnectionString,
                        StorageContainerName
                        );

                // Registers the Event Processor Host and starts receiving messages
                eventProcessorHost.RegisterEventProcessorAsync<Helper.EventProcessor>(); 
            }
            catch (Exception ex)
...

拋出異常

eventProcessorHost.RegisterEventProcessorAsync<Helper.EventProcessor>(); 

但是,此問題似乎與Azure事件中心無關。 因為在嘗試創建Application Insights事件時,我也在global.asax.cs也遇到了此異常:

new TelemetryClient().TrackEvent("Application started");

我知道還有其他一些關於“請求在這種情況下不可用”的例外的帖子,但這似乎是VS2017的特殊行為。

我的本地環境是:

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.16) Release
VisualStudio.15.Release/15.2.0+26430.16
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Visual C# 2017   00369-60000-00001-AA377
Microsoft Visual C# 2017

Application Insights Tools for Visual Studio Package   8.6.00404.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30503.0
ASP.NET and Web Tools 2017

ASP.NET Web Frameworks and Tools 2017   5.2.50303.0

Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0

Common Azure Tools   1.9

根據您的描述,我一邊創建了ASP.NET 4.5.2 Azure API App應用程序,然后使用以下命令在VS2015(企業版14.0.25431.01更新3)和VS2017(企業預覽版15.3.0預覽版7.1)上對其進行了調試IIS Express(10.0.14358.100),都可以成功調試,並且可以將自定義事件和指標發送給我的應用程序見解。

根據您的問題,我建議您通過VS啟動應用程序而不進行調試來縮小此問題,或者您可以使用cmd.exe並運行iisexpress /path:"c:\\myapp\\" /port:80來檢查您的應用程序是否可以按預期工作。

我卸載了VS2017的所有組件,然后重新安裝了最新的版本15.3.3。 現在代碼開始運行。 不知道第一次安裝出了什么問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM