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

Script compilations not specifying a return type take an implicit dependency on the host corlib #8506

Closed
abock opened this issue Feb 9, 2016 · 2 comments · Fixed by #8507
Assignees
Milestone

Comments

@abock
Copy link
Contributor

abock commented Feb 9, 2016

When "cross compiling" a script for a corlib different from the "host", if a return type is not specified, System.Object from the host (via typeof(object)) is reflection-loaded.

This makes it impossible to target a script on a different corlib (e.g. Xamarin.iOS) from the host without explicitly specifying a returnType: via CreateScriptCompilation.

Example:

const string corlibPath = "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/mscorlib.dll";
var compilation = CSharpCompilation.CreateScriptCompilation (
    assemblyName: "Script",
    syntaxTree: CSharpSyntaxTree.ParseText (
        text: "true",
        options: new CSharpParseOptions (kind: SourceCodeKind.Script)),
    references: new [] { MetadataReference.CreateFromFile (corlibPath) },
    options: new CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary));
Debug.Assert (compilation.GetDiagnostics ().Length == 0);

This will result in the diagnostic:

(1,1): error CS0400: The type or namespace name 'System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be found in the global namespace (are you missing an assembly reference?)

This is due to the compilation falling back (because returnType: is not specified via CreateScriptCompilation) to typeof(object) for SynthesizedInteractiveInitializerMethod's Task<> return type type argument, which will be the host corlib's System.Object and not the System.Object from the Xamarin.iOS (or any other non-host-compatible) corlib.

@ManishJayaswal
Copy link
Contributor

#8507 will hopefully resolve this issue.

@abock
Copy link
Contributor Author

abock commented May 4, 2016

I've just finally gotten around to updating #8507 to account for the last round of feedback and rebased it on today's master. I hope we can get this merged. We need this in Xamarin Workbooks and have been shipping a patched version of Roslyn with the patch since February.

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

Successfully merging a pull request may close this issue.

4 participants