dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

Extension not decompiling nuget packages right SqlCommand & SqlReader #6394

Open sant123 opened 12 months ago

sant123 commented 12 months ago

Environment data

dotnet --info output:

.NET SDK:
 Version:   7.0.110
 Commit:    ba920f88ac

Runtime Environment:
 OS Name:     fedora
 OS Version:  38
 OS Platform: Linux
 RID:         fedora.38-x64
 Base Path:   /usr/lib64/dotnet/sdk/7.0.110/

Host:
  Version:      7.0.10
  Architecture: x64
  Commit:       a6dbb800a4

.NET SDKs installed:
  7.0.110 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.10 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.10 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib64/dotnet]

global.json file:
  Not found

VS Code version: 1.82.2 C# Extension version: v2.1.2

Steps to reproduce

  1. Install this package https://www.nuget.org/packages/Microsoft.Data.SqlClient/5.1.1
  2. Write this code
using Microsoft.Data.SqlClient;

var builder = new SqlConnectionStringBuilder
{
    DataSource = "localhost",
    UserID = "sa",
    Password = "",
    InitialCatalog = ""
};

try
{
    using var connection = new SqlConnection(builder.ConnectionString);

    Console.WriteLine("\nQuery data example:");
    Console.WriteLine("=========================================\n");

    connection.Open();

    var sql = "SELECT name, age FROM People";

    using var command = new SqlCommand(sql, connection);
    using var reader = command.ExecuteReader();

    while (reader.Read())
    {
        Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetInt32(1));
    }
}
catch (SqlException e)
{
    Console.WriteLine(e);
}

Console.WriteLine("\nDone. Press enter.");
  1. Ctrl + Click the ExecuteReader method

Expected behavior

Decompiled library successfully with intellisense working

Actual behavior

image

Notice there is no type inference for SqlDataReader and its return type is null

Additional context

When getting intellisense for reader, the list is not complete. In this case is missing the Dispose() method.

image

Looking at SqlClient source code for v5.1.1 the method is defined without a [EditorBrowsable(EditorBrowsableState.Never)] data annotation so it should be showed.

Also tested with VS Code C# Extension v1.26.0, it works but the decompiling is different compared to the source.

dibarbet commented 12 months ago

When getting intellisense for reader, the list is not complete. In this case is missing the Dispose() method.

The method linked is protected so it doesn't show up in intellisense. The actual Dispose method it would bind to is inSystem.Data.Common.DbDataReader which does have the attribute.

So this is by design.

Decompiled library successfully with intellisense working

Not sure exactly what is happening here, but its likely an issue in ICSharpCode.Decompiler which we use to decompile. I've noticed the same issue reproduces in VS as well. There's probably not much we can do on the extension side.

I see ILSpy is also unable to decompile this, so almost certainly a bug or limitation on their end.

image
sant123 commented 12 months ago

The method linked is protected so it doesn't show up in intellisense. The actual Dispose method it would bind to is inSystem.Data.Common.DbDataReader which does have the attribute.

@dibarbet thanks for pointing me out. Now I see the attribute but I'm curious why should not be shown in intellisense?

I think we may remove the [EditorBrowsable(EditorBrowsableState.Never)] data annotation.

I see ILSpy is also unable to decompile this, so almost certainly a bug or limitation on their end.

So perhaps we may create an issue in order to them can look into?