Skip to content

VS Debugger does not retrieve source code from Bitbucket Data Center #1493

Open

Description

@tj-mkunz

For several days I have been trying to get Source Link to work with my company's Bitbucket Data Center instance, but with no success so far.

The package
I have created a NuGet package "sourceLinkTest" with the following project file (some details replaced by [...]):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <Title>Use to verify Source Link functionality</Title>
    <SignAssembly>False</SignAssembly>
    <AssemblyVersion>1.0.5</AssemblyVersion>
    <FileVersion>$(AssemblyVersion)</FileVersion>
    <Version>$(AssemblyVersion)</Version>
    <Company>[...]</Company>
    <RepositoryUrl>https://bitbucket.[...]/scm/tjcomplayg/sourcelinktest.git</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
    <IncludeSymbols>False</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>embedded</DebugType>
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DebugType>none</DebugType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.Bitbucket.Git" Version="8.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

The resulting package looks fine in the NuGet Package Explorer:

  • Health -> Source Link: Valid
  • Repository -> Type: git
  • Repository -> Url: https://bitbucket.[...]/projects/tjcomplayg/repos/sourcelinktest/browse
  • Package contents -> sourceLinkTest.dll -> PDB Sources contains https://bitbucket.[...]/projects/tjcomplayg/repos/sourcelinktest/raw/ExceptionalClass.cs?at=aa00542ad8ee5d37a1ff69ac6a128dc6f88c1289. In a browser, this URL yields the raw source code of the file ExceptionalClass.cs, provided that I am authenticated via SSO.

The sourcelink CLI tool gives mixed results:

PS C:\Temp> sourcelink print-urls .\sourceLinkTest.dll
68c4166a442cfa9751843e5e2d5d9c06414ba32666fed9f4c64a1a7e114c8b5f sha256 csharp /_/ExceptionalClass.cs
https://bitbucket.[...]/projects/tjcomplayg/repos/sourcelinktest/raw/ExceptionalClass.cs?at=aa00542ad8ee5d37a1ff69ac6a128dc6f88c1289
f3f134e9e825e3e7268090f58b1af2bda2de513f61a09c56f48b9b8d08612abc sha256 csharp /_/obj/Debug/net8.0/sourceLinkTest.GlobalUsings.g.cs
embedded
f7a5d9789c863625e139ff99e1113a503830f6b85a88f6129916df83ac76b49e sha256 csharp /_/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
embedded
40a4271744bf84ef21d98d0c91d7dd61bb4f10d5394df12fb2983a610dda5d76 sha256 csharp /_/obj/Debug/net8.0/sourceLinkTest.AssemblyInfo.cs
embedded

looks fine, but

PS C:\Temp> sourcelink test .\sourceLinkTest.dll
1 Documents with errors:
68c4166a442cfa9751843e5e2d5d9c06414ba32666fed9f4c64a1a7e114c8b5f sha256 csharp /_/ExceptionalClass.cs
https://bitbucket.[...]/projects/tjcomplayg/repos/sourcelinktest/raw/ExceptionalClass.cs?at=aa00542ad8ee5d37a1ff69ac6a128dc6f88c1289
error: url hash does not match: 68c4166a442cfa9751843e5e2d5d9c06414ba32666fed9f4c64a1a7e114c8b5f
sourcelink test failed

does not. I assume that the authentication is the problem here.

The application
Project file of my .NET 8.0 test application:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="sourceLinkTest" Version="1.0.5" />
  </ItemGroup>

</Project>

When the app is loaded, I call a constructor from sourceLinkTest that throws an exception. For my tests I start my app with the Visual Studio Debugger attached.

Expectation
When the exception is thrown, the debugger displays the code containing the throw statement (= source code of the package).

Observation
When the exception is thrown, the highlighted line is where the constructor is called (= source code of the app), not the place where the exception is thrown (= source code of the package). If I "Go to [the] definition" of the constructor, I see disassembled code, not the original source.

Debug output
I see zero output related to Source Link in the Debug output pane, especially no HTTP status code.
However, for about two seconds a dialog is displayed saying

Locating Source
The debugger is locating source files. Please wait.
/ _/ExceptionalClass.cs"

Do you have any suggestions how to further debug this issue and get Source Link working?

Activity

  1. tmat commented on Oct 30, 2025

    @tmat
    Member
  2. chuckries commented on Nov 4, 2025

    @chuckries
    Contributor

    @tj-mkunz BitBucket is not officially supported in any capacity, but has worked in the past. I am not familiar with the current state of BitBucket Data Center auth mechanics. One thing you can try is to enable the Debug > Options > General > Fall back to Git Credential Manager authentication for Source Link request. A helpful artifact would be a network trace (like fiddler) to see exactly what VS is sending for auth and how BitBucket is failing.

  3. tj-mkunz commented on Mar 5, 2026

    @tj-mkunz
    Author

    First of all, sorry for the long silence.

    @chuckries Thanks for your sugggestions. I used HTTP toolkit instead of fiddler. This is my first attempt of HTTPS network tracing, so please let me know if I need to change my approach. The free version of HTTP Toolkit does not provide an export function, so I copied the info by hand. Like before, I have replaced some details by [...].

    Network traces

    Visual Studio sourceLinkTestApp, „Fall back to Git Credential Manager authentication for all Source Link requests“ deactivated

    No requests are made, neither to Bitbucket, nor to any other host.

    Visual Studio sourceLinkTestApp, „Fall back to Git Credential Manager authentication for all Source Link requests“ activated

    Method Host Path and query Status Location header (response)
    HEAD https://bitbucket.[...] / 302 https://bitbucket.[...]/dashboard
    HEAD https://bitbucket.[...] /dashboard 302 https://bitbucket.[...]/login?nextUrl=%2Fdashboard
    HEAD https://bitbucket.[...] /login?nextUrl=%2Fdashboard 302 https://bitbucket.[...]/plugins/servlet/saml/auth
    HEAD https://bitbucket.[...] /plugins/servlet/saml/auth 302 https://[...].okta.com/app/[...]_bitbucketprod_1/exk2twnlukkn64TSV357/sso/saml?SAMLRequest=jZJP[...]
    HEAD https://[...].okta.com /app/[...]_bitbucketprod_1/exk2twnlukkn64TSV357/sso/saml?SAMLRequest=jZJP[...] 200

    Okta is our Single Sign On provider. If I visit the URL in a private browser window, I see the standard login screen.

    After about 2 s, the same sequence is repeated once. Another 2 s after the last request, source code retrieval fails and the debugger highlights the line where the constructor is called.

    Cloning a git repo via HTTPS

    Method Host Path and query Auhorization header (request) Status Location header (response)
    GET https://bitbucket.[...] /scm/tjcomplayg/sourcelinktest.git/info/refs?service=git-upload-pack 401
    GET https://bitbucket.[...] /scm/tjcomplayg/sourcelinktest.git/info/refs?service=git-upload-pack Basic 200
    HEAD https://bitbucket.[...] / HPE_INVALID_CONSTANT
    HEAD https://bitbucket.[...] /dashboard
    https://bitbucket.\[...\]/login?nextUrl=%2Fdashboard
    HEAD https://bitbucket.[...] /login?nextUrl=%2Fdashboard 302 https://bitbucket.\[...\]/plugins/servlet/saml/auth
    HEAD https://bitbucket.[...] /plugins/servlet/saml/auth ECONNRESET
    POST https://bitbucket.[...] /scm/tjcomplayg/sourcelinktest.git/git-upload-pack Basic 200
    GET https://bitbucket.[...] /scm/tjcomplayg/sourcelinktest.git/info/refs?service=git-upload-pack 401
    GET https://bitbucket.[...] /rest/authconfig/1.0/login-options 200
    GET https://bitbucket.[...] /rest/oauth2/1.0/client 401
    GET /rest/api/1.0/users Bearer 200
    GET /scm/tjcomplayg/sourcelinktest.git/info/refs?service=git-upload-pack Basic 200
    HEAD / HPE_INVALID_CONSTANT
    HEAD /dashboard 302 https://bitbucket.[...]/login?nextUrl=%2Fdashboard
    HEAD /login?nextUrl=%2Fdashboard 302 https://bitbucket.[...]/plugins/servlet/saml/auth
    HEAD /plugins/servlet/saml/auth ECONNRESET
    POST /scm/tjcomplayg/sourcelinktest.git/git-upload-pack Basic 200
    POST /scm/tjcomplayg/sourcelinktest.git/git-upload-pack Basic 200

    With that last request and response the repository is cloned

    Summary

    1. Without Git Credential Manager, no attempt is made to retrieve the source code of the package.
    2. If Git Credential Manager is activated, Visual Studio does contact the correct Bitbucket server, but gets stuck when it reaches the login page of our SSO provider.
    3. However, non-interactive access to the repository is possible, as is can be seen in the git clone trace.

    What now? Is there anything I can do to make SourceLink work?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions