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

5

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.

Sentient answered 16/11, 2016 at 18:49 Comment(5)
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.)Rambow
that is what I have found as well, just no work around is working for me yetSentient
it also appears a nuget-packaged csc.exe (Microsoft .NET) is being used to compile instead of mcs (Mono)Rambow
Are you overriding the CscToolExe property? The default should be mcs.exe. What kind of projects are you seeing this issue with?Clarsach
any project which includes <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net45" developmentDependency="true" /> 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.Rambow
R
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

Rambow answered 16/11, 2016 at 19:27 Comment(4)
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...Wilbert
The NON-HACK option works well for me, but I should also remove code from csproj: <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" .....Michaelamichaele
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 issueGarceau
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.Crystacrystal
C
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.

Clarsach answered 18/11, 2016 at 1:15 Comment(2)
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)"Maquis
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!Rambow
M
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"

Maquis answered 10/12, 2016 at 22:41 Comment(0)
D
1

After I deleted the line

<DebugType>pdbonly</DebugType>

from the .csproj file, the build became successful.

Dudek answered 30/5, 2019 at 7:59 Comment(0)
H
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.

Heaney answered 22/1, 2019 at 1:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.