Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeSystem.Object brings mscorlib assembly reference on .NET Core #524

Closed
ddizh opened this issue Jun 18, 2018 · 4 comments
Closed

TypeSystem.Object brings mscorlib assembly reference on .NET Core #524

ddizh opened this issue Jun 18, 2018 · 4 comments

Comments

@ddizh
Copy link

ddizh commented Jun 18, 2018

I'm on netcoreapp2.0 with Mono.Cecil 0.10.0 and noticed that the given line of code

new TypeDefinition(assemblyName, "Main", TypeAttributes.Class | TypeAttributes.Public, module.TypeSystem.Object);

produces following IL:

.class public auto ansi Main extends [mscorlib]System.Object

with these assembly references:

.assembly extern mscorlib
{
  .ver 4:0:0:0
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
}
.assembly extern System.Private.CoreLib
{
  .ver 4:0:0:0
  .publickeytoken = (7C EC 85 D7 BE A7 79 8E )
}

but AFAIK mscorlib stands for full framework and since im on .NET Core I expect it to be either System.Private.CoreLib or System.Runtime only. I assume that Mono.Cecil resolves TypeSystem.Object to mscorlib somewhere in the code implicitly despite the selected platform.
Am I getting it right? If so, please push me in the right direction on how to explicitly route everything to System.Private.CoreLib. Otherwise, please explain the idea.

@jbevain
Copy link
Owner

jbevain commented Jun 18, 2018

Cecil's TypeSystem type will try to find a «core library» in your module to use (with mscorlib or System.Private.CoreLib being such a library), and if it doesn't find one it will create a reference to mscorlib.

Before adding a type, is there an existing reference to mscorlib in your dll? Cecil will pick a mscorlib over a System.Private.Corelib.

@jbevain
Copy link
Owner

jbevain commented Jun 18, 2018

@ddizh
Copy link
Author

ddizh commented Jun 19, 2018

@jbevain I see where System.Private.CoreLib comes from in my code.
It was typeof(string[]) in here:

new ParameterDefinition("args", ParameterAttributes.None, module.ImportReference(typeof(string[])));

If I remove this, I will end up with only mscorlib assembly reference left due to TypeSystem.Object piece.
I'm going to dig into the source code you've mentioned to see how to force Cecil to use System.Private.CoreLib out of TypeSystem.Object by default instead of mscorlib, thanks.

@jbevain
Copy link
Owner

jbevain commented Jun 19, 2018

You can use TypeSystem.String and wrap that in a new ArrayType. I'm closing this but feel free to re-open if you get specific issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants