当使用Visual Studio 2017进行调试时,“请求在此上下文中不可用”
我从Visual Studio 2015升级到Visual Studio 2017.下面的代码在部署到Azure应用服务并运行Visual Studio 2015但在Visual Studio 2017年调试时,它抛出异常:当使用Visual Studio 2017进行调试时,“请求在此上下文中不可用”
请求不可用在这方面
对于VS2015和VS2017 IIS Express用于调试。现在安装了VS2017 IIS 10.0 Express(10.0.1737),我不记得VS2015使用了哪个版本。
代码是基于ASP.NET 4.5.2 Azure API应用程序模板的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的活动中心。因为我试图创建一个应用程序洞察事件时得到此异常也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)和带有IIS Express(10.0.14358.100)的VS2017(Enterprise Preview V15.3.0 Preview 7.1),都可以成功进行调试,并且可以将自定义事件和指标发送给我的应用程序洞察。
根据您的问题,我建议你开始通过VS您的应用程序而不调试,以缩小这一问题,或者您可以使用cmd.exe
和运行iisexpress /path:"c:\myapp\" /port:80
检查预期应用程序是否能正常工作。
我卸载了所有组件的VS2017,并重新安装了最新的15.3.3版本。现在代码运行。不知道第一次安装时出了什么问题。
您是否认为您的Web应用程序中的相同代码可以在vs2015而非vs2017下进行本地调试?你安装的IIS Express版本是什么?我曾经在我的ApiController中调用TrackEvent。 –
是的,vs2017,vs2015和部署到Azure App Service时的代码完全相同。使用vs2017我正在运行IIS 10.0 Express(10.0.1737)。 集成了解决方案的管理管道模式。 –