0

I have the following class:

/// <summary>
///     Represents an implementation of the <see cref="IAspNetCoreLoggingConfigurationBuilder"/> to configure the ASP.NET Core Logging.
/// </summary>
public class AspNetCoreLoggingConfigurationBuilder : IAspNetCoreLoggingConfigurationBuilder
{
    #region Properties

    /// <summary>
    ///     Gets the <see cref="ILogSource"/> that's used to write log entries.
    /// </summary>
    public ILogSource LogSource{ get; private set; }

    #endregion

    #region IAspNetCoreLoggingConfigurationBuilder Members

    /// <summary>
    ///     Sets the log source that should be used to save log entries.
    /// </summary>
    /// <param name="logSource">The source </param>
    public void SetLogSource(ILogSource logSource)
    {
        LogSource = logSource;
    }

    #endregion
}

I also have a method in which I create an instance of this class:

/// <summary>
///     Adds logging to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to configure the application's request pipeline.</param>
/// <param name="configuration">Builder used to configure the ASP.NET Core Logging.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseAspNetCoreLogging(this IApplicationBuilder app, Action<IAspNetCoreLoggingConfigurationBuilder> configuration)
{
    var aspNetLoggerConfiguration = new AspNetCoreLoggingConfigurationBuilder();

    configuration(aspNetLoggerConfiguration);

    // Add the registered ILogSource into the registered services.
    _services.AddInstance(typeof (ILogSource), aspNetLoggerConfiguration.LogSource);

    // The entire configuration for the middleware has been done, so return the middleware.
    return app.UseMiddleware<AspNetCoreLoggingMiddleware>();
}

Notice the first line here, I'm creating an instance of the class. However, when I inspect this variable in a watch, when my cursor is on line configuration(aspNetLoggerConfiguration); I do get that the variable does not exists in the current context.

Creating an instance of the variable does work when doing it directly in the watch window.

Anyone has a clue?

P.S. It's a DNX project which I'm testing in xUnit. The code is running in 'Debug' mode.

Complexity
  • 5,682
  • 6
  • 41
  • 84

1 Answers1

0

Thats no runtime and no compiling-error. It's a problem of Visual Studio not beeing able to show the object in a debug-window as it is a runtime-object (something like that).

Another occurence of this problem is in a wcf-service client. Create a new serviceclient Client and try to show client.InnerChannel in the watch window. It won't work. You can however create a temp-object (bool, string, etc..) and write the desired value into it to see your value.

#if DEBUG
    var tmpLog = aspNetLoggerConfiguration.LogSource;
#endif

You should see the LogSource in the tmpLog when your mouse is over it.

Marcel B
  • 508
  • 2
  • 9
  • I just added the above line after the definition and I do get "tmpLog does not exist in the current context. – Complexity Apr 06 '16 at 10:42
  • For testing. I added these lines as the first one in an xUnit unit test: `var loggingConfiguration = new AspNetCoreLoggingConfigurationBuilder(); var demo = loggingConfiguration;`. Guess what, both properties are empty. It's really driving my nuts. If I place an empty constructor in the `AspNetCoreLoggingConfigurationBuilder`, the code is executed, I'm stepping in the constructor, however, when returning, the value is null. – Complexity Apr 06 '16 at 10:45
  • From what you are telling me, i can just guess what could be another possible Problem, but to be honest, i have no idea why your program is behaving like this. – Marcel B Apr 06 '16 at 10:49
  • I don't think it has anything to do with my application. In Visual Studio, I create a new ASP.NET 5 website (thus DNX project), I add the following line in "Configure". `var demo = new Demo();` where `Deom` is anmpty class. However, when running, demo is null. – Complexity Apr 06 '16 at 10:52