Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Affected: Mono JIT compiler version 5.0.1 (Visual Studio built mono)
Possibly related to https://bugzilla.xamarin.com/show_bug.cgi?id=51609
Invoking `ICodeCompiler.CompileAssemblyFromFile` unconditionally produces the security exception for CSharpCodeProvider form Microsoft.CodeDom.Providers.DotNetCompilerPlatform v1.0.4 (https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform). This nuget package supposed to be the only way to use ICodeCompiler bound to Roslyn compilers. The test project is attached.
Steps to reproduce: build exe from the test project and launch it under mono.
The problem affects both Windows and Linux and effectively it means that on Mono ICodeCompiler targeting C# 7 (Roslyn) cannot be used at all.
The exception "System.Security.SecurityException: Couldn't impersonate token." is always thrown from System.dll (v22.214.171.124):
public static int ExecWaitWithCapture(IntPtr userToken, string cmd, string currentDir, TempFileCollection tempFiles, ref string outputName, ref string errorName)
return InternalExecWaitWithCapture(cmd, currentDir, tempFiles, ref outputName, ref errorName);
By using Reflection I managed to bypass WindowsIdentity.Impersonate and call InternalExecWaitWithCapture directly and it does solve the problem. Well at least the 'CompileAssemblyFromFile' succeeded.
This work around is very similar to the one that Razor team resorted to: https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Compilation/DirectCompilerServiceBase.cs (line 323)
Accidental duplicate of #57130
*** This bug has been marked as a duplicate of bug 57130 ***