Skip to content

GetProjectOptionsFromScript raises Internal CLR error #15970

Closed
@nojaf

Description

@nojaf

Another SDK release, another lament.

I'm using fsdocs which processes some scripts to generate HTML. What worked yesterday, stopped working after I downloaded dotnet 8 RC 1.

Fatal error. Internal CLR error. (0x80131506)
   at System.Runtime.Serialization.SerializationGuard.<ThrowIfDeserializationInProgress>g__ThrowIfDeserializationInProgress|0_0(System.Runtime.Serialization.SerializationInfo, System.String, Int32 ByRef)
   at System.Diagnostics.Process.Start()
   at <StartupCode$FSharp-Compiler-Service>.$FxResolver.executeProcess$cont@56(System.String, System.String, Microsoft.FSharp.Core.FSharpOption`1<System.String>, Int32, Microsoft.FSharp.Core.Unit)
   at FSharp.Compiler.FxResolver.executeProcess(System.String, System.String, Microsoft.FSharp.Core.FSharpOption`1<System.String>, Int32)
   at <StartupCode$FSharp-Compiler-Service>[email protected](System.String)
   at System.Collections.Concurrent.ConcurrentDictionary`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.FSharp.Core.FSharpResult`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].GetOrAdd(System.__Canon, System.Func`2<System.__Canon,Microsoft.FSharp.Core.FSharpResult`2<System.__Canon,System.__Canon>>)
   at FSharp.Compiler.FxResolver.tryGetDesiredDotNetSdkVersionForDirectoryInfo()
   at FSharp.Compiler.FxResolver.tryGetDesiredDotNetSdkVersionForDirectory()
   at <StartupCode$FSharp-Compiler-Service>[email protected](Microsoft.FSharp.Core.Unit)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at FSharp.Compiler.FxResolver.tryGetSdkDir()
   at <StartupCode$FSharp-Compiler-Service>[email protected](Microsoft.FSharp.Core.Unit)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at FSharp.Compiler.FxResolver.getImplementationAssemblyDir()
   at <StartupCode$FSharp-Compiler-Service>[email protected](Microsoft.FSharp.Core.Unit)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at FSharp.Compiler.FxResolver.tryGetNetCoreRefsPackDirectoryRoot()
   at <StartupCode$FSharp-Compiler-Service>[email protected](Microsoft.FSharp.Core.Unit)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at FSharp.Compiler.FxResolver.tryGetSdkRefsPackDirectory()
   at <StartupCode$FSharp-Compiler-Service>[email protected](FSharp.Compiler.FxResolverLockToken)
   at Internal.Utilities.Library.Lock`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].AcquireLock[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>)
   at FSharp.Compiler.FxResolver.GetDefaultReferences(Boolean)
   at FSharp.Compiler.ScriptClosure+ScriptPreprocessClosure.CreateScriptTextTcConfig[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, System.String, System.String, CodeContext, Boolean, Boolean,
 Microsoft.FSharp.Core.FSharpOption`1<System.Tuple`2<System.__Canon,Microsoft.FSharp.Collections.FSharpList`1<System.Tuple`2<PhasedDiagnostic,FSharp.Compiler.Diagnostics.FSharpDiagnosticSeverity>>>>, Microsoft.FSharp.Core.FSharpFunc`2<TcConfigBuilder,Microsoft.FSharp.Core.Unit>, Boolean, Boolean, Microsoft.FSharp.Core.FSharpOption`1<System.String>, Microsoft.FSharp.Core.FSharpFunc`2<System.Tuple`2<System.String,System.DateTime>,Microsoft.FSharp.Core.FSharpOption`1<System.Tuple`3<System.Object,IntPtr,Int32>>>, ReduceMemoryFlag)
   at FSharp.Compiler.ScriptClosure+ScriptPreprocessClosure.GetFullClosureOfScriptText(FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, System.String, System.String, FSharp.Compiler.Text.ISourceText, CodeContext, Boolean, Boolean, Boolean, Microsoft.FSharp.Core.FSharpOption`1<System.String>, LexResourc
eManager, Microsoft.FSharp.Core.FSharpFunc`2<TcConfigBuilder,Microsoft.FSharp.Core.Unit>, Boolean, Microsoft.FSharp.Core.FSharpFunc`2<System.Tuple`2<System.String,System.DateTime>,Microsoft.FSharp.Core.FSharpOption`1<System.Tuple`3<System.Object,IntPtr,Int32>>>, ReduceMemoryFlag, FSharp.Compiler.DependencyManager.DependencyProvider)
   at FSharp.Compiler.ScriptClosure+LoadClosure.ComputeClosureOfScriptText(FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, System.String, System.String, FSharp.Compiler.Text.ISourceText, CodeContext, Boolean, Boolean, Boolean, Microsoft.FSharp.Core.FSharpOption`1<System.String>, LexResourceManager, Mi
crosoft.FSharp.Core.FSharpFunc`2<TcConfigBuilder,Microsoft.FSharp.Core.Unit>, Boolean, Microsoft.FSharp.Core.FSharpFunc`2<System.Tuple`2<System.String,System.DateTime>,Microsoft.FSharp.Core.FSharpOption`1<System.Tuple`3<System.Object,IntPtr,Int32>>>, ReduceMemoryFlag, FSharp.Compiler.DependencyManager.DependencyProvider)
   at <StartupCode$FSharp-Compiler-Service>[email protected](System.Threading.CancellationToken)
   at Internal.Utilities.Library.Cancellable+toAsync@898-1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(System.Threading.CancellationToken)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Threading.CancellationToken, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.AsyncActivation`1<System.__Canon>, System.Threading.CancellationToken, Microsoft.FSharp.Core.FSharpFunc`2<System.Threading.CancellationToken,Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>>)
   at Microsoft.FSharp.Control.Trampoline.Execute(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.AsyncReturn>)
   at Microsoft.FSharp.Control.AsyncPrimitives.RunImmediate[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Threading.CancellationToken, Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>)
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Threading.CancellationToken, Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>, Microsoft.FSharp.Core.FSharpOption`1<Int32>)
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>, Microsoft.FSharp.Core.FSharpOption`1<Int32>, Microsoft.FSharp.Core.FSharpOption`1<System.Threading.CancellationToken>)
   at FSharp.Formatting.Internal.CompilerServiceExtensions+FSharpAssemblyHelper+getNetCoreAppFrameworkDependencies@71.Invoke(Microsoft.FSharp.Core.Unit)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at FSharp.Formatting.Internal.CompilerServiceExtensions+FSharpAssemblyHelper.getCheckerArguments[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon, System.__Canon, Boolean, Microsoft.FSharp.Core.FSharpOption`1<System.String>, System.Collections.Generic.IEnumerable`1<System.String>, System.Collections.Generic.IEnumerable`1<System.String>, System.Collections.Generic.IEnumerable`1<System.String>)
   at FSharp.Formatting.CodeFormat.CodeFormatter+processSourceCode@353-1.Invoke(System.IO.StringReader)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.AsyncActivation`1<System.__Canon>, System.__Canon, Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>>)
   at Microsoft.FSharp.Control.Trampoline.Execute(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.AsyncReturn>)
   at <StartupCode$FSharp-Core>[email protected](System.Object)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Process finished with exit code -1,073,741,819

Repro steps

  • Install the RC 1 SDK
  • Create console application
  • Add reference to FCS (dotnet add package FSharp.Compiler.Service --version 43.8.100-preview.23418.2)
  • Update Program.fs:
open System.IO
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text

let checker = FSharpChecker.Create()

let tempFile = Path.GetTempFileName() |> (fun p -> Path.ChangeExtension(p, ".fsx"))
printfn "%s" tempFile
File.Create(tempFile).Dispose()

let options =
    checker.GetProjectOptionsFromScript(
        tempFile,
        SourceText.ofString "",
        assumeDotNetFramework = false
    )
    |> Async.RunSynchronously

File.Delete tempFile

printfn "%A" options

Expected behaviour

I'm able to get the project options.

Actual behaviour

This is failing to execute dotnet --version in

let executeProcess pathToExe arguments (workingDir: string option) timeout =
if not (String.IsNullOrEmpty pathToExe) then
let errorsList = ResizeArray()
let outputList = ResizeArray()
let mutable errorslock = obj
let mutable outputlock = obj
let outputDataReceived (message: string MaybeNull) =
match message with
| Null -> ()
| NonNull message -> lock outputlock (fun () -> outputList.Add(message))
let errorDataReceived (message: string MaybeNull) =
match message with
| Null -> ()
| NonNull message -> lock errorslock (fun () -> errorsList.Add(message))
let psi = ProcessStartInfo()
psi.FileName <- pathToExe
if workingDir.IsSome then
psi.WorkingDirectory <- workingDir.Value
psi.RedirectStandardOutput <- true
psi.RedirectStandardError <- true
psi.Arguments <- arguments
psi.CreateNoWindow <- true
psi.EnvironmentVariables.Remove("MSBuildSDKsPath") // Host can sometimes add this, and it can break things
psi.UseShellExecute <- false
use p = new Process()
p.StartInfo <- psi
p.OutputDataReceived.Add(fun a -> outputDataReceived a.Data)
p.ErrorDataReceived.Add(fun a -> errorDataReceived a.Data)
if p.Start() then
p.BeginOutputReadLine()
p.BeginErrorReadLine()
if not (p.WaitForExit(timeout)) then
// Timed out resolving throw a diagnostic.
raise (TimeoutException(sprintf "Timeout executing command '%s' '%s'" psi.FileName psi.Arguments))
else
p.WaitForExit()
#if DEBUG
if workingDir.IsSome then
FileSystem
.OpenFileForWriteShim(Path.Combine(workingDir.Value, "StandardOutput.txt"))
.WriteAllLines(outputList)
FileSystem
.OpenFileForWriteShim(Path.Combine(workingDir.Value, "StandardError.txt"))
.WriteAllLines(errorsList)
#endif
p.ExitCode, outputList.ToArray(), errorsList.ToArray()
else
-1, Array.empty, Array.empty

Fatal error. Internal CLR error. (0x80131506)

What is very frustrating is that the unit tests in

[<TestCase(false, false, [| "--targetprofile:mscorlib" |])>]
[<TestCase(false, true, [| "--targetprofile:mscorlib" |])>]
[<TestCase(true, true, [| "--targetprofile:mscorlib" |])>]
[<TestCase(false, false, [| "--targetprofile:netstandard" |])>]
[<TestCase(false, true, [| "--targetprofile:netstandard" |])>]
[<TestCase(true, true, [| "--targetprofile:netstandard" |])>]
[<TestCase(false, false, [| "--targetprofile:netcore" |])>]
[<TestCase(false, true, [| "--targetprofile:netcore" |])>]
[<TestCase(true, true, [| "--targetprofile:netcore" |])>]
[<Test>]
let ``can generate options for different frameworks regardless of execution environment - useSdkRefs = false``(assumeDotNetFramework, useSdkRefs, flags) =
let path = Path.GetTempPath()
let file = tryCreateTemporaryFileName () + ".fsx"
let tempFile = Path.Combine(path, file)
let _, errors =
checker.GetProjectOptionsFromScript(tempFile, SourceText.ofString scriptSource, assumeDotNetFramework = assumeDotNetFramework, useSdkRefs = useSdkRefs, otherFlags = flags)
|> Async.RunImmediate
match errors with
| [] -> ()
| errors -> failwithf "Error while parsing script with otherFlags:%A:\n%A" flags errors

are still working for me on my local machine.

Known workarounds

/

Related information

Provide any related information (optional):

  • Operating system Windows 11
  • .NET Runtime: .NET 8 rc 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.Resolution-External

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions