Home

CompilationOptions ctor error when using Microsoft.CodeAnalysis - MissingMethodException

edited August 2016
Latest VS 2015 Community (downloaded this morning) and Linqpad (downloaded a couple of days ago) gives errors in the CompilationOptions constructors in "C# 6.0 in a Nutshell - Chapter 27" compilation samples. Seems like they should work. It looks like the constructor takes an OutputKind and then a bunch of defaulted values but "new CSharpCompilationOptions (OutputKind.ConsoleApplication)" seems to give an error using the samples out of the box.

Comments

  • edited August 2016
    Microsoft.CodeAnalysis.CSharp.dll references System.Collections.Immutable 1.1.37.0, whereas the NuGet package includes v1.2.0.0 of the latter.

    You can verify this as follows:
    typeof (CSharpCompilationOptions).Assembly.GetReferencedAssemblies().Single (a => a.Name == "System.Collections.Immutable").Version.Dump();
    
    The difficulty arises if you've got 1.1.37.0 installed in the GAC. Despite NuGet wanting to use the later version, the GAC reference loads automatically and takes precedence, and you get the MissingMethodException.
  • Thanks so much and pardon my ignorance on this matter, but what should I do next? Put the 1.2.0.0 version in the GAC? Remove the 1.1.37.0 version from the GAC? Change the code in the sample? I've been trying to look up whether replacing the version in the GAC would cause problems and how I would do that. I haven't really been able to figure anything out so far. I'm sure you're far more familiar with this stuff than I am so would love to hear any ideas you might have. Thanks so much for a GREAT product and for your GREAT support in the forums!
  • edited August 2016
    There's a workaround that you can use right now.

    Go to Query | App.Config (Ctrl+Shift+O). Click 'Let me type it in' and paste the following in:
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    To avoid having to do this for every query that uses Roslyn assemblies, click the 'Save as snippet' button and choose a short name such as 'roslyn'. Then with any query, you'll just have to type roslyn followed by the tab key, and you'll get the roslyn assemblies, the namespace imports and the app.config settings added to your query in one hit.

    In terms of a permanent solution, I'm not sure on how (and whether) to proceed - I guess it depends on whether this is a one-off or a recurring problem.
  • Update: the 5.09.02 LINQPad beta fixes this automatically:
    https://www.linqpad.net/Download.aspx#beta

    It now identifies the problem scenario and creates binding redirects on the fly.
Sign In or Register to comment.