question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DependencyContext.Default is null under mono

See original GitHub issue

Steps to reproduce

Program.cs file

using System;
using Microsoft.Extensions.DependencyModel;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(DependencyContext.Default == null);
        }
    }
}

project.json file:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.Extensions.DependencyModel": "1.0.0-rc2-final"
  },
  "frameworks": {
    "net451": {
    }
  }
}

run dotnet run --framework net451.

Expected behavior

console output as False.

Actual behavior

console output as True:

Project hwdotnet (.NETFramework,Version=v4.5.1) will be compiled because inputs were modified
Compiling hwdotnet for .NETFramework,Version=v4.5.1

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:03.1174645


True

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64

mono:

Mono JIT compiler version 4.4.0 (Stable 4.4.0.148/fcf7a6d Thu Apr 28 14:51:58 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pakrymcommented, May 24, 2016

‘preserveCompilationContext’ should be set to ‘true’ in ‘buildOptions’ to get ‘DependencyContext’ on full framework.

2reactions
Sharpirocommented, Feb 19, 2017

@pakrym @davidfowl DependencyContext.Default always returns null when executing from a .csproj of the “old stack” even though everything builds correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DependencyContext.Default throws error in.net core Test ...
DependencyContext.Default uses Assembly.GetEntryAssembly() to probe for assemblies to load. For the running ASP.NET Core app under Kestrel, ...
Read more >
DependencyContext.Default Property
Gets the dependency context for the current application.
Read more >
C# (CSharp) DependencyContext Examples
Default, compileLibraries: new CompilationLibrary[] { } ... Assembly); if (dependencyContext != null) { foreach (var library in dependencyContext.
Read more >
C# (CSharp) DependencyContext.GetDefaultAssemblyNames ...
<summary> /// Initializes a new instance of the <see cref="DependencyContextAssemblyProvider" /> class. /// </summary> /// <param name="context">The ...
Read more >
Porting a .Net Framework Library to .Net Core
I have recently been involved with porting a couple of open source ... It includes just two sections, projects and sdk by default....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found