2

Context

VS 2019, .NET Core 3 Preview 5. I've created a brand new ASP MVC Web App. Now examining the StartUp code:

// ...
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
//...

When I try to see what those extension methods are doing I go to the source (in my case ctrl+click and that invokes JetBrain decompiler) I get this:

// Decompiled with JetBrains decompiler
// Type: Microsoft.AspNetCore.Builder.AuthAppBuilderExtensions
// Assembly: Microsoft.AspNetCore.Authentication, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// MVID: A1CE531C-37CE-4C8A-B143-24C2AC9CFE19
// Assembly location: C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.0.0-preview5-19227-01\ref\netcoreapp3.0\Microsoft.AspNetCore.Authentication.dll

namespace Microsoft.AspNetCore.Builder
{
  /// <summary>
  /// Extension methods to add authentication capabilities to an HTTP application pipeline.
  /// </summary>
  public static class AuthAppBuilderExtensions
  {
    /// <summary>
    /// Adds the <see cref="T:Microsoft.AspNetCore.Authentication.AuthenticationMiddleware" /> to the specified <see cref="T:Microsoft.AspNetCore.Builder.IApplicationBuilder" />, which enables authentication capabilities.
    /// </summary>
    /// <param name="app">The <see cref="T:Microsoft.AspNetCore.Builder.IApplicationBuilder" /> to add the middleware to.</param>
    /// <returns>A reference to this instance after the operation has completed.</returns>
    public static IApplicationBuilder UseAuthentication(
      this IApplicationBuilder app)
    {
      throw null;
    }
  }
}

Question

When I debug the code, I get no Exception so it seems not that code is running. My conclusion, that what the project refers those are dummy empty assemblies, (see the // Assembly location: C:\Program Files... comment line in the decompiled source) but I do not understand the mechanism why runtime other assemblies will be loaded?

Can anyone explain what actually happening here?

georges619
  • 288
  • 1
  • 6
  • 18
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • Are you debugging the decompiled code as described here: https://stackoverflow.com/a/32788309/3212610 ? – AirLancer May 08 '19 at 05:36
  • @JohanP The decompiler is correct, I literally went to that assembly (see the Assembly location comment in the decompiled source) and Reflector also decompiles all methods to "throw null". The question is what are those dummy assemblies, and what is that mechanism that ensures that runtime not those dummies, instead real implementations will be loaded (and from where?) – g.pickardou May 08 '19 at 05:44
  • 2
    Those are reference assemblies. Meant to compile against, not to be run. The implemention is in the `Microsoft.AspNetCore.Authentication.dll` in your bin directory. – CodeCaster May 08 '19 at 06:55
  • See also https://stackoverflow.com/questions/9701135/reference-assemblies-folder-and-different-assemblies-with-the-same-version, https://github.com/dotnet/docs/issues/2638 – CodeCaster May 08 '19 at 07:01
  • @CodeCaster: Thx, you are right. Still not clear a) what is the use this "dummy" reference assemblies, why we don't compile against the real ones? b) Why Resharper decompiles these dummies, when it is clear to the build tooling to what concrete others to output, so it should be for Resharper too... – g.pickardou May 08 '19 at 09:04
  • @g.pickardou if you're waiting for R# to be smart and consequent in its doing, I can only tell you I'm waiting since years. – springy76 May 29 '19 at 07:44
  • @springy76: I realize that, so I am open to any alternative solution, what navigates me to the source in the described case – g.pickardou May 29 '19 at 08:42
  • 1
    @CodeCaster is it possible to tell the decompiler not to open the `ref` dll, but the `src` dll ? – Legends Sep 30 '19 at 21:50

0 Answers0