Type system reference in dotnetcore?

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

To compile a single program in dotnetcore, we obviously have to reference some assemblies, which implement at least the type system. Because the dotnetcore is build as set of nuget packages, it is required to explicitly (at least for now) reference all required assemblies.
For example, take a look on this code:

using System;

public class Program

{
   
public static void
Main()
    {
       
int
a = 32;
   
}
}


This code is simplest possible application, you can write. It is even simpler than writing to console.
If you try to compile it with dependency to dnxcore50, as shown below, you will not be able to compile the program.

{

  "dependencies": { 

 

  },

  "commands": {

    "ConsoleApp": "ConsoleApp"

  },

  "frameworks": {

    "dnxcore50": {    }

  }

}

Here are few errors, which you will get:

DNX Core 5.0 error CS0518: Predefined type 'System.Object' is not defined or imported
DNX Core 5.0 error CS0518: Predefined type 'System.Void' is not defined or imported
DNX Core 5.0 error CS0518: Predefined type 'System.String' is not defined or imported
DNX Core 5.0 error CS0518: Predefined type 'System.Object' is not defined or imported

This is because all required assemblies must be referenced. This does not make as right now very productive, because we still do not have tools, which adds references automatically, but it is a correct behavior. This reduce dramatically the footprint of application and makes it easier for deployment without unneeded references.

To fix this problem, extend the project.json file as shown in next example:

{

  "dependencies": { 

 

  },

  "commands": {

    "ConsoleApp": "ConsoleApp"

  },

  "frameworks": {

    "dnxcore50": {

      "dependencies": {

        "System.Runtime": "4.0.21-beta-23220" 

      }

    }

  }

}

Not that build number is in this case not that important and it will be probably obsolete, when you read this post. This is the version of runtime which I used at the moment of writing of this post.

This is the assembly, which is always referenced by all of assemblies in the framework. If you take a look on following picture, you will figure out, that all system assemblies (I peeked some of them) has a reference to System.Runtime.

image


Posted Sep 08 2015, 07:20 AM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.