16

Just downloaded Visual Studio Professional for Mac and I cannot seem to build anything as I always get the same error:

/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) ->

CSC: error CS0041: Unexpected error writing debug information -- 'Operation is not supported on this platform.'

 19 Warning(s)
 1 Error(s)

Not sure what to change on my project to get things to compile.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Slee
  • 27,498
  • 52
  • 145
  • 243
  • this seems to be related to producing PDB files? this has hit me as well, although this occurs without the use of `visual-studio-mac` (it's a problem with xbuild, I only experience this on one project, a web/asp.net project which builds on Windows fine, and then hosts on Mac fine, but doesn't build on mac.) – Shaun Wilson Nov 16 '16 at 19:12
  • that is what I have found as well, just no work around is working for me yet – Slee Nov 16 '16 at 19:16
  • it also appears a nuget-packaged `csc.exe` (Microsoft .NET) is being used to compile instead of `mcs` (Mono) – Shaun Wilson Nov 16 '16 at 19:17
  • Are you overriding the `CscToolExe` property? The default should be `mcs.exe`. What kind of projects are you seeing this issue with? – radical Nov 17 '16 at 17:45
  • 1
    any project which includes `` will have this problem -- fix likely requires modification of this compiler for mono/xamarin/mac platform/env. as a long-time .NET developer I don't much care which compiler is used, as long as it works and the resulting images are debuggable when they're done compiling. – Shaun Wilson Nov 17 '16 at 21:51

5 Answers5

24

I was able to work around this problem two ways:

  1. HACK By removing debug symbols from the build (in VS windows: Project Properties -> Build Tab -> Advanced button -> change "Debug Info" dropdown to "none" -- not sure what equivalent is in VS for Mac / Xamarin Studio) I did this for all configurations of affected project(s). Pulled back to macOS env, build now succeeds. No debug info of course, but it works without breaking any deps.

  2. NON-HACK Root cause is the use of Roslyn compiler/tools for ASP.NET Web projects, and this tool produces PDB files instead of MDB files, and the build fails trying to produce PDB files on macOS platform (er go "platform unsupported".) Knowing the root cause we can also remove the following nuget packages from the affected projects:

    <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net45" />
    <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net45" developmentDependency="true" />
    

It's unclear what is sacrificed by removing these two packages. This does allow me to build the affected projects with the debug info included. The affected projects only contained webapi endpoints, and no use of MVC nor Razor engine. It would be nice to hear the experiences of others if they had issues upstream from this change.

HTH

Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
  • I have the same dilemma - I am trying to get a CI process on MONO to run and it fails on Roslyn-related compiler issues. I only have a pure WebAPI2 porject (with an Angular2 front-end) - I have removed all Roslyn compiler links and that seems to work but I am not fully understanding the implications... – Rodney Feb 12 '17 at 17:47
  • 1
    The NON-HACK option works well for me, but I should also remove code from csproj: – Cairo Mar 17 '18 at 17:43
  • I was experiencing the same issue using `mono:5.12.0.226` image in docker on a linux container host when trying to build an ASP.NET MVC (.NET v4.5.2). Option #2 solved my issue – Samuel Slade Jun 29 '18 at 10:08
  • Adding `/p:DebugType=None` to `msbuild` would do the same as the "HACK" variant, but might be useful in e.g. CI pipelines which just check if it compiles at all. – debuglevel Jan 24 '23 at 16:09
7

This is a bug that will be fixed shortly. Meanwhile, you can edit your csproj file to add

<DebugType Condition="'$(OS)' != 'Windows_NT'">portable</DebugType>

after the line with <DebugType>full</DebugType> or <DebugType>pdbonly</DebugType>

Essentially, we want the DebugType property on Mac to be portable, which is supported by Roslyn's csc.exe on non-windows platforms, instead of pdb.

radical
  • 4,364
  • 2
  • 25
  • 27
  • 4
    Just tried this, and got the following error when building in VS 2016 for Mac: "Error CS1902: Invalid option 'portable' for /debug; must be full or pdbonly (CS1902)" – Icet Dec 10 '16 at 22:33
  • Is there a connect() issue or similar we can track this bug with, I am still using one of the other workarounds mentioned here, and not sure if/how this is backlogged/tracked (ie. how will we know when it's working as intended?) Thanks! – Shaun Wilson Jan 02 '17 at 20:11
5

To solve this problem you need to do :

  1. Select project

  2. Right click and select options

  3. Select tab Build -> Compiler
  4. Debug information -> None

It solved this error but gives me another one

"System.IO.FileNotFoundException Could not find file "/Users/.../.../bin\roslyn\csc.exe"

Icet
  • 678
  • 2
  • 13
  • 31
1

After I deleted the line

<DebugType>pdbonly</DebugType>

from the .csproj file, the build became successful.

Darius
  • 441
  • 1
  • 5
  • 13
0

I hope not to come too late, I did the following to solve the problem:

  1. Right click in the solution and select "Options",

  2. Select tab Build -> Configurations,

  3. In "Configuration A." select "Debug" and disable all builds marks and click accept,

  4. Clean, rebuild and execute project.

I hope this helps.

Alex Bravo
  • 1,601
  • 2
  • 24
  • 40