CSharpScript.EvaluateAsync(..) throws AccessViolationException

I'm trying to filter some objects from my CLI with the following command:

project some-object list --filter="x => x.Name == 'someNewName'"

this calls the following code:

    resource.Filter = resource.Filter.Replace("'", "\"");
    var filterScriptOptions = ScriptOptions.Default.AddReferences(typeof(SomeObject).Assembly);

    CAUSES EXCEPTION
    ---------------------------------------
    var filterExpression = CSharpScript.EvaluateAsync<Func<SomeObject, bool>>(resource.Filter, 
    filterScriptOptions).Result;
    ---------------------------------------


    entities = entities.Where(filterExpression).ToList();

when i do that the following error message comes up:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.CodeAnalysis.ClrGlobalAssemblyCache.CreateAssemblyEnum(IAssemblyEnum ByRef, IApplicationContext, IAssemblyName, ASM_CACHE, IntPtr)
   at Microsoft.CodeAnalysis.ClrGlobalAssemblyCache.CreateAssemblyEnum(IAssemblyEnum ByRef, IApplicationContext, IAssemblyName, ASM_CACHE, IntPtr)
   at Microsoft.CodeAnalysis.ClrGlobalAssemblyCache+<GetAssemblyObjects>d__12.MoveNext()
   at Microsoft.CodeAnalysis.FusionAssemblyIdentity.GetBestMatch(System.Collections.Generic.IEnumerable`1<IAssemblyName>, System.String)
   at Microsoft.CodeAnalysis.ClrGlobalAssemblyCache.ResolvePartialName(System.String, System.String ByRef, System.Collections.Immutable.ImmutableArray`1<System.Reflection.ProcessorArchitecture>, System.Globalization.CultureInfo)
   at Microsoft.CodeAnalysis.Scripting.Hosting.GacFileResolver.Resolve(System.String)
   at Microsoft.CodeAnalysis.Scripting.Hosting.RuntimeMetadataReferenceResolver.ResolveMissingAssembly(Microsoft.CodeAnalysis.MetadataReference, Microsoft.CodeAnalysis.AssemblyIdentity)
   at Microsoft.CodeAnalysis.CommonReferenceManager`2[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryResolveMissingReference(Microsoft.CodeAnalysis.MetadataReference, Microsoft.CodeAnalysis.AssemblyIdentity, System.Collections.Immutable.ImmutableDictionary`2<Microsoft.CodeAnalysis.AssemblyIdentity,Microsoft.CodeAnalysis.PortableExecutableReference> ByRef, Microsoft.CodeAnalysis.MetadataReferenceResolver, Microsoft.CodeAnalysis.DiagnosticBag, Microsoft.CodeAnalysis.AssemblyIdentity ByRef, Microsoft.CodeAnalysis.AssemblyMetadata ByRef, Microsoft.CodeAnalysis.PortableExecutableReference ByRef)
   at Microsoft.CodeAnalysis.CommonReferenceManager`2[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ResolveAndBindMissingAssemblies(System.__Canon, System.Collections.Immutable.ImmutableArray`1<AssemblyData<System.__Canon,System.__Canon>>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.PEModule>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.MetadataReference>, System.Collections.Immutable.ImmutableArray`1<ResolvedReference<System.__Canon,System.__Canon>>, Microsoft.CodeAnalysis.MetadataReferenceResolver, Microsoft.CodeAnalysis.MetadataImportOptions, Boolean, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<AssemblyReferenceBinding<System.__Canon,System.__Canon>[]>, System.Collections.Generic.Dictionary`2<System.String,System.Collections.Generic.List`1<ReferencedAssemblyIdentity<System.__Canon,System.__Canon>>>, System.Collections.Immutable.ImmutableArray`1<AssemblyData<System.__Canon,System.__Canon>> ByRef, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.MetadataReference> ByRef, System.Collections.Immutable.ImmutableArray`1<ResolvedReference<System.__Canon,System.__Canon>> ByRef, System.Collections.Immutable.ImmutableDictionary`2<Microsoft.CodeAnalysis.AssemblyIdentity,Microsoft.CodeAnalysis.PortableExecutableReference> ByRef, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CommonReferenceManager`2[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Bind(System.__Canon, System.Collections.Immutable.ImmutableArray`1<AssemblyData<System.__Canon,System.__Canon>>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.PEModule>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.MetadataReference>, System.Collections.Immutable.ImmutableArray`1<ResolvedReference<System.__Canon,System.__Canon>>, Microsoft.CodeAnalysis.MetadataReferenceResolver, Microsoft.CodeAnalysis.MetadataImportOptions, Boolean, System.Collections.Generic.Dictionary`2<System.String,System.Collections.Generic.List`1<ReferencedAssemblyIdentity<System.__Canon,System.__Canon>>>, System.Collections.Immutable.ImmutableArray`1<AssemblyData<System.__Canon,System.__Canon>> ByRef, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.MetadataReference> ByRef, System.Collections.Immutable.ImmutableArray`1<ResolvedReference<System.__Canon,System.__Canon>> ByRef, System.Collections.Immutable.ImmutableDictionary`2<Microsoft.CodeAnalysis.AssemblyIdentity,Microsoft.CodeAnalysis.PortableExecutableReference> ByRef, Microsoft.CodeAnalysis.DiagnosticBag, Boolean ByRef, Int32 ByRef)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation+ReferenceManager.CreateAndSetSourceAssemblyFullBind(Microsoft.CodeAnalysis.CSharp.CSharpCompilation)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation+ReferenceManager.CreateSourceAssemblyForCompilation(Microsoft.CodeAnalysis.CSharp.CSharpCompilation)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetBoundReferenceManager()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.get_SourceAssembly()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.get_Assembly()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.get_SourceModule()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.get_CommonSourceModule()
   at Microsoft.CodeAnalysis.Compilation.CommonBindScriptClass()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.BindScriptClass()
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Value()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.get_ScriptClass()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetEntryPointAndDiagnostics(System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetEntryPoint(System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetEntryPoint(System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.Build[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.Compilation, Microsoft.CodeAnalysis.DiagnosticBag, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.CreateExecutor[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.Scripting.ScriptCompiler, Microsoft.CodeAnalysis.Compilation, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetExecutor(System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunAsync(System.Object, System.Func`2<System.Exception,Boolean>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunAsync(System.Object, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.RunAsync[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.String, Microsoft.CodeAnalysis.Scripting.ScriptOptions, System.Object, System.Type, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.EvaluateAsync[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.String, Microsoft.CodeAnalysis.Scripting.ScriptOptions, System.Object, System.Type, System.Threading.CancellationToken)
   at Project.Cli.Domains.SomeObjects.SomeObjectsResourceHandler.List(Project.Cli.Domains.SomeObjects.SomeObjectsResource, System.Collections.Generic.List`1<Project.Cli.Domains.SomeObjects.Dtos.SomeObject> ByRef)
   at Project.Cli.Domains.SomeObjects.SomeObjectsResourceHandler.Handle(Project.Cli.Domains.SomeObjects.SomeObjectsResource)
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
   at Project.Cli.Domains.IResourceHandlerExtensionMethods.Handle(Project.Cli.Domains.IResourceHandler, Project.Cli.Domains.IResource)
   at Project.Cli.Program+<>c__DisplayClass1_0.<ParseAndHandleCommands>b__0(System.Object)
   at CommandLine.ParserResultExtensions.WithParsed[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](CommandLine.ParserResult`1<System.__Canon>, System.Action`1<System.__Canon>)
   at Project.Cli.Program.ParseAndHandleCommands(System.String[], System.IServiceProvider, System.Type[])
   at Project.Cli.Program.Main(System.String[])

this worked until i updated .NET Core from 2.1 to 3.1 but going back to 2.1 isn't an option for me.

i also tried adding

[HandleProcessCorruptedStateExceptions]
[SecurityCritical]

at the top of the executed function but with no use.