`System.AccessViolationException` opening default aws-cdk fsharp template
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
[AWS-CDK](https://docs.aws.amazon.com/cdk/v2/guide/cli.html) offers a (not officially supported) [FSharp template](https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk/lib/init-templates/app/fsharp).
When using this template and opening it in VSCode with Ionide, after restoring dependencies, opening FSharp files in the project doesn't function (e.g. tooltips, hints), `System.AccessViolationException` message can be found in the `F#` output log and the extension appears to be crashed (from that point it doesn't work for other .fs files even if they aren't from the template).
Although the issue is occurring in VSCode the exception stacktrace appears to suggest an FSharp compiler issue.
**Repro steps**
Detailed repro steps are provided in a repo: https://github.com/chrissimon-au/fcs-AccessViolationException-repro
The commit history itemises the steps used to create the repository, and the README describes steps to reproduce the errors.
**Expected behavior**
FSharp files in the cdk template project should work like normal FSharp files with hover, hints, autocomplete, etc.
**Actual behavior**
No normal functions and `System.AccessViolationException` exceptions in the log.
**Known workarounds**
See repro repo: https://github.com/chrissimon-au/fcs-AccessViolationException-repro#workarounds
**Related information**
All details are in the reproduction repository as it uses a vscode devcontainer:
1. DotNet 6.0 (`dotnet:0-6.0-bullseye`)
2. CDK version:
cdk version
2.83.1 (build 006b542)
3. Reproduced with Ionide v7.5.4 (current release version) and v7.6.1 (current pre-release version)
The full error log is:
```
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Buffer.Memmove(Byte ByRef, Byte ByRef, UIntPtr)
at System.IO.UnmanagedMemoryStream.WriteCore(System.ReadOnlySpan`1)
at FSharp.Compiler.IO.MemoryMappedFileExtensions+MemoryMappedFile-TryFromByteMemory-Static@390.Invoke(System.IO.MemoryMappedFiles.MemoryMappedViewStream)
at FSharp.Compiler.IO.MemoryMappedFileExtensions.trymmf(Int64, Microsoft.FSharp.Core.FSharpFunc`2)
at FSharp.Compiler.IO.MemoryMappedFileExtensions.MemoryMappedFile.TryFromByteMemory.Static(FSharp.Compiler.IO.ReadOnlyByteMemory)
at FSharp.Compiler.IO.ByteStorage.FromByteMemoryAndCopy(FSharp.Compiler.IO.ReadOnlyByteMemory, Boolean)
at FSharp.Compiler.AbstractIL.ILBinaryReader.seekReadManifestResources(ILMetadataReader, Boolean, FSharp.Compiler.IO.ReadOnlyByteMemory, PEReader, FSharp.Compiler.IO.ReadOnlyByteMemory)
at FSharp.Compiler.AbstractIL.ILBinaryReader.seekReadModule(ILMetadataReader, Boolean, PEReader, FSharp.Compiler.IO.ReadOnlyByteMemory, UInt16, System.Tuple`2, Boolean, Boolean, Boolean, Boolean, Boolean, Microsoft.FSharp.Core.FSharpOption`1, Boolean, Int32, Int32, Int32, System.String, Int32)
at FSharp.Compiler.AbstractIL.ILBinaryReader.openMetadataReader(System.String, BinaryFile, Int32, System.Tuple`8,Boolean,Boolean,Boolean,Boolean,Boolean,System.Tuple`5,Boolean,Int32,Int32,Int32>>, PEReader, FSharp.Compiler.IO.ReadOnlyByteMemory, Microsoft.FSharp.Core.FSharpOption`1, Boolean)
at FSharp.Compiler.AbstractIL.ILBinaryReader.OpenILModuleReader(System.String, ILReaderOptions)
at FSharp.Compiler.CompilerImports+TcImports.OpenILBinaryModule(Internal.Utilities.Library.CompilationThreadToken, System.String, FSharp.Compiler.Text.Range)
at FSharp.Compiler.CompilerImports+TryRegisterAndPrepareToImportReferencedDll@2142-2.Invoke(ProjectAssemblyDataResult)
at FSharp.Compiler.BuildGraph+Bind@61-1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(System.__Canon)
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.AsyncActivation`1, System.__Canon, Microsoft.FSharp.Core.FSharpFunc`2>)
at Microsoft.FSharp.Control.Trampoline.Execute(Microsoft.FSharp.Core.FSharpFunc`2)
at Microsoft.FSharp.Control.AsyncPrimitives.StartWithContinuations[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Threading.CancellationToken, Microsoft.FSharp.Control.FSharpAsync`1, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2)
at Microsoft.FSharp.Control.FSharpAsync.StartWithContinuationsUsingDispatchInfo[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.FSharpAsync`1, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpOption`1)
at Microsoft.FSharp.Control.FSharpAsync.StartWithContinuations[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.FSharpAsync`1, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpFunc`2, Microsoft.FSharp.Core.FSharpOption`1)
at FSharp.Compiler.BuildGraph+GetOrComputeValue@365-5[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(Microsoft.FSharp.Core.Unit)
at FSharp.Compiler.BuildGraph+Bind@61-1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(System.__Canon)
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.AsyncActivation`1, System.__Canon, Microsoft.FSharp.Core.FSharpFunc`2>)
at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr, Void (IntPtr, IntPtr, System.Runtime.CompilerServices.PortableTailCallFrame*), IntPtr)
at .$CompilerServiceInterface+ParseAndCheckFileInProject@302-5.Invoke(Microsoft.FSharp.Control.AsyncActivation`1>)
at Microsoft.FSharp.Control.Trampoline.Execute(Microsoft.FSharp.Core.FSharpFunc`2)
at .$Async+clo@208-16.Invoke(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
```
Contributor guide
Assessment
This issue has not been assessed yet.