roslyn: Cannot compile PDB on Mono - CS0041: Unexpected error writing debug information -- 'The method or operation is not implemented.'

There is sample:

using System;
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace TestR
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            var code = @"                        
                        namespace TestR
                        {
                            class MainClass
                            {
                                public static void AAA (string[] args)
                                {
                                }
                            }
                        }
                        ";

            var syntaxTree = CSharpSyntaxTree.ParseText(code);

            var references = new [] {
                MetadataReference.CreateFromFile (typeof(Type).Assembly.Location)
            };

            var compilation = CSharpCompilation.Create(
                "assembly",
                new[] {syntaxTree},
                references,
                new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));


            using (var ms = new MemoryStream ())
            using (var pdbs = new MemoryStream ()) 
            {
                var result = compilation.Emit (ms, pdbs);

                if (!result.Success) 
                {
                    throw new Exception ("Not compiled: " + result.Diagnostics[0]);
                }

                Console.WriteLine ("Compiled and saved");
            }
        }
    }
}

But if I remove pdbs from compilation.Emit (ms, pdbs) that will compile successfully. Running without mono all works.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I’m sorry to be an idiot, but where do you set the DebugInformationFormat option? Is this in the csproj somewhere?

@castrojr913 Does setting debug type in .csproj fix the issue?

<DebugType>portable</DebugType>

It’s 2020 now and this type is still not supported by the latest version of VS for MAC

@golfguy0082 I had the same problem with a .NET 4.6 solution compiling on macOS. For this, I found the document “Portable PDB’s” in the OmniSharp repo which explains this a bit.

Basically put, you can set this in the .csproj file:

<DebugType>portable</DebugType>

Or, it if’s a dotnet core project, set it in the project.json:

"buildOptions": {
    "debugType": "portable"
}

portablepdb’s seems to be a new thing introduced with dotnet core, so results may very depending on your IDE.