繁体   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