Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Application Insights to an ASP.NET Core application breaks auto-detect-url when launching debugger #2177

Closed
d3r3kk opened this issue Apr 11, 2018 · 4 comments

Comments

@d3r3kk
Copy link

d3r3kk commented Apr 11, 2018

Launching the VSCode C# debugger after adding ApplicationInsights SDK to my ASP.NET Core application fails.

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.104)
Product Information:
Version:            2.1.104
Commit SHA-1 hash:  48ec687460
Runtime Environment:
OS Name:     Windows
OS Version:  10.0.16299
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\2.1.104\
Microsoft .NET Core Shared Framework Host
Version  : 2.0.6
Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

VS Code version:

Version 1.21.1
Commit 79b44aa704ce542d8ca4a3cc44cfca566e7720f1
Date 2018-03-14T14:46:47.128Z
Shell 1.7.9
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

C# Extension version: 1.14.0

Steps to reproduce

  1. Open command window

  2. Create a folder for my app, and enter that folder.

    ] dotnet new react
    ] dotnet add nuget
    ] dotnet sources add -Name "nuget.org" -Source https://api.nuget.org/v3/index.json
    ] dotnet add .\TestVsCodeDotNet.csproj package Microsoft.ApplicationInsights.AspNetCore

  3. Open VSCode in my new folder.

  4. Using the tasks.json & launch.json that get auto-generated from templates in VSCode, build and launch the debugger by pressing F5.

Expected behavior

Debugging session starts, my browser is opened, and I can see & debug my application.

Actual behavior

Debugging session starts.

Window pops up:
[Window Title]
http://localhost:Development
[Content]
Windows cannot find 'http://localhost:Development'. Make sure you typed the name correctly, and then try again.
[OK]

Console reads:

Launching browser (cmd.exe /C start http://localhost:"Development)
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.NodeServices[0]
      webpack built f051b69f57976ffe99fa in 4000ms
Microsoft.AspNetCore.NodeServices:Information: webpack built f051b69f57976ffe99fa in 4000ms
The thread 1548 has exited with code 0 (0x0).
The thread 12284 has exited with code 0 (0x0).

Sometimes the "Launching browser" line reads:
Launching browser (cmd.exe /C start http://localhost:"true)
and sometimes it reads:
Launching browser (cmd.exe /C start http://localhost:"Development)

Note: I can launch the browser manually and navigate to http://localhost:5000, and continue debugging.

Workaround (may need local changes to correct port)

I determined that this line in launch.json is where the problem is manifesting itself:

"launchBrowser": {
  "enabled": true,
  "args": "${auto-detect-url}",
  "windows": {
    "command": "cmd.exe",
    "args": "/C start ${auto-detect-url}"
  },

At this point I noticed that the url is being ‘auto-generated’ to http://localhost:”true, but the console reads Launching browser (cmd.exe /C start http://localhost:5000)
… suggesting that the ‘auto-detect-url’ is failing in VSCode (or in the Omnisharp-csharp extension) for some reason.
I started Fiddler to see if I could sort anything out from this, and that didn’t show anything obvious.

I changed my launch.json section for “launchBrowser” to the following:

"launchBrowser": {
  "enabled": true,
  "args": **"http://localhost:5000",**
  "windows": {
    "command": "cmd.exe",
    "args": "/C start **http://localhost:5000"**
  },

Now things are working. This is my current proposed workaround.

Details that might help troubleshoot

The problem seems to rest with VSCode debugging process and not Application Insights (we’ve simply exposed an issue with the ${auto-detect-url} declaration in the launch.json. From reading a few things on the github repo’s for VSCode and for Omnisharp-vscode I understand that the url is being determined by inspecting stdout somehow.

The ApplicationInsights SDK is injecting a telemetry line into the stdout stream prior to the launch of the browser, and that line contains some values related to localhost. This may be getting the stdout parsing confused. Here’s my sample stdout stream that causes the issue, note the 2nd line containing the injected Application Insights telemetry:

Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.6\System.IO.Compression.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Application Insights Telemetry: {"name":"Microsoft.ApplicationInsights.Dev.e0f750b063854d9b96b94a896793d54e.RemoteDependency","time":"2018-04-11T17:20:00.6540970Z","iKey":"89506ec2-e0cd-4d66-8d52-726ac1cc7237","tags":{"ai.application.ver":"1.0.0.0","ai.cloud.roleInstance":"LAPTOP01","ai.operation.id":"efbeb370-44999dca9b749635","ai.internal.sdkVersion":"rdddsc:2.5.1-195","ai.internal.nodeName":"LAPTOP01"},"data":{"baseType":"RemoteDependencyData","baseData":{"ver":2,"name":"POST /","id":"|efbeb370-44999dca9b749635.","data":"http://localhost:58738","duration":"00:00:02.0372735","resultCode":"200","success":true,"type":"Http","target":"localhost","properties":{"AspNetCoreEnvironment":"Development","DeveloperMode":"true"}}}}
Loaded 'C:\Program Files\dotnet\store\x64\netcoreapp2.0\microsoft.extensions.localization.abstractions\2.0.2\lib\netstandard2.0\Microsoft.Extensions.Localization.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\store\x64\netcoreapp2.0\microsoft.aspnetcore.jsonpatch\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.JsonPatch.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.6\System.Collections.Immutable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\store\x64\netcoreapp2.0\microsoft.extensions.hosting.abstractions\2.0.2\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Hosting environment: Development
Content root path: C:\dev\vsts\mycode\TestVsCodeDotNet
Launching browser (cmd.exe /C start http://localhost:"true)
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.NodeServices[0]
      webpack built f051b69f57976ffe99fa in 4213ms
Microsoft.AspNetCore.NodeServices:Information: webpack built f051b69f57976ffe99fa in 4213ms
The system cannot find the file http://localhost:true.

Update: removed formatting in stdout log

@gregg-miskelly
Copy link
Contributor

Thanks for the report!

@d3r3kk
Copy link
Author

d3r3kk commented Apr 27, 2018

@gregg-miskelly would you like me to try and repro this on insiders or something?

@gregg-miskelly
Copy link
Contributor

This is an issue with the C# extension, so insiders will not change anything. There will be a beta of the C# extension out very soon (today or Monday) that has the fix if you want to verify. The release of 1.15 is also expected pretty soon. So if you aren't in a rush you can just wait for that.

@d3r3kk
Copy link
Author

d3r3kk commented Apr 27, 2018

Cool, I'll watch for it and give it a go when 1.15 comes out then. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants