roslyn: Roslyn cannot work in netstandard dll?

I need to encapsulte Roslyn into a netstandard dll for fx47 and core11 clients.

Source code are available at: https://github.com/scegg/CSharpRoslynHelper

The code to compile in Roslyn:

using System;
using System.Collections.Generic;
using System.Reflection;

namespace UserCode
{
    public class UserCodeClass
    {
        public bool Check(string message)
        {
            List<string> x = new List<string>();
            GenericMethod((dynamic)x);
            Console.WriteLine(message);
            return true;
        }

        public void GenericMethod<T>(List<T> data)
        {
            var implant = new Implant<object>();
            implant.Print(data);
        }
    }

    public class Implant<TClass>
    {
        public void Print<TArg>(List<TArg> list)
        {
            var result = string.Format(""TClass: {0} ({1})\nTArg: {2} ({3})"", typeof(TClass).Name, typeof(TClass).GetTypeInfo().Assembly.CodeBase, typeof(TArg).Name, typeof(TArg).GetTypeInfo().Assembly.CodeBase);
            Console.WriteLine(result);
        }
    }
}

The assemblies provided with the code: Microsoft.CSharp, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Linq, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Version Used: VS 2017 15.2 26430.16 Class library for encapsulate Roslyn: Standard 1.3 Nuget: Microsoft.CodeAnalysis.CSharp 2.3.1 Roslyn won’t read from disk for assembly. All assemblies will be provided as byte[] from caller. App referenced this class library: Core 1.1 Console

Steps to Reproduce:

  1. Get code from github https://github.com/scegg/CSharpRoslynHelper
  2. Select CoreTest-Direct to run.
  3. Check the error. Id: CS0656; Message: Missing compiler required member ‘Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’

Expected Behavior: The error should not exists coz Microsoft.CSharp is referenced.

Actual Behavior: Error.

Actually, non of 4 tests in this solution can work… Projects in this solution are: CSharpRoslynHelper: The encapsulate of Roslyn, in netstardard 1.3 ShandardLibraryAsProxy: A proxy, in netstandard 1.5 and netfx 47, which is designed to provide the images of all required assemblies requested from CSharpRoslynHelper. CoreTest-ByProxy: Core11 Console App, references ShandardLibraryAsProxy and provide the code only. CoreTest-Direct: Core11 Console App, references CSharpRoslynHelper and provide images of all required assemblies. Fx47Test-ByProxy: netfx47 Console App, references ShandardLibraryAsProxy and provide the code only. Fx47Test-Direct: netfx47 Console App, references CSharpRoslynHelper and provide images of all required assemblies.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Now using all from TRUSTED_PLATFORM_ASSEMBLIES and dotnet standard 2.0, no problem currently.