Sdk: DependencyContext.Default is null under mono

Created on 24 May 2016  路  6Comments  路  Source: dotnet/sdk

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

Most helpful comment

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

All 6 comments

/cc @pakrym

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

@tugberkugurlu I'm going to close the issue. If @pakrym's suggestion did not help please let us know and we'll reopen.

@pakrym, @piotrpMSFT works as expected after having _"preserveCompilationContext": true_ :+1:

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

That's because it relies on a specific file existing in the output that the old tool chain does not produce

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joffreykern picture joffreykern  路  3Comments

thomaslevesque picture thomaslevesque  路  3Comments

moozzyk picture moozzyk  路  3Comments

natemcmaster picture natemcmaster  路  3Comments

dasMulli picture dasMulli  路  3Comments