0

This question is about internals of assembly references.

.Net Core 1.1 Hello world console application assembly (created from dotnet new console) emits no reference to mscorlib, only to System.Runtime and System.Console, and yet it emits call to [mscorlib]System.Console.

How is that possible?

.assembly extern System.Runtime
{
  .ver 4:1:0:0
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
}
.assembly extern System.Console
{
  .ver 4:0:0:0
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
}
.assembly 'console1'
...
.class private auto ansi beforefieldinit Program
    extends [System.Runtime]System.Object
...
    IL_0006:  call void class [mscorlib]System.Console::WriteLine(string)

...
Ivan
  • 1,552
  • 1
  • 16
  • 25
  • Which version of the tooling are you using? if I try to reproduce this with 1.0.4, I get `call void [System.Console]System.Console::WriteLine(string)` – Martin Ullrich Jun 10 '17 at 09:06
  • @MartinUllrich Current .Net Core 1.1 which comes with tooling 1.0.4. I'm using Mac – Ivan Jun 10 '17 at 15:03
  • @HansPassant do you know where this would come in here? the reference assembly that is compiled against is built from https://github.com/dotnet/corefx/blob/master/src/System.Console/ref/System.Console.cs in this case – Martin Ullrich Jun 10 '17 at 21:29

1 Answers1

0

It turns out to be a bug in disassembly tool.

Since .NET Core doesn't come with ildasm I used monodis from Mono. Now I followed .net-core: Equivalent of ILDASM / ILASM to compile ildasm for Mac form C++ sources, and now:

$ monodis bin/Debug/netcoreapp1.1/console1.dll | grep WriteLine
    IL_0006:  call void class [mscorlib]System.Console::WriteLine(string)
$ ildasm bin/Debug/netcoreapp1.1/console1.dll | grep WriteLine
    IL_0006:  call       void [System.Console]System.Console::WriteLine(string)
Ivan
  • 1,552
  • 1
  • 16
  • 25