Roslyn executions hanging when called with large objects

0

I built this wrapper around Roslyns scripting API ...

using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Workflow
{
    internal class ScriptRunner : IScriptRunner
    {
        internal static Assembly[] references;

        public ScriptRunner()
        {
            references = ...;  
        }

        public async Task<T> Run<T>(string code, string[] imports, object args)
        {
            var referencesNeeded = references.Where(r => r.GetExportedTypes().Any(t => imports.Contains(t.Namespace)));
            var options = ScriptOptions.Default
                .AddReferences(referencesNeeded)
                .WithImports(imports);

            return await CSharpScript.EvaluateAsync<T>(code, options, args, args.GetType());
        }

        public Task Run(string code, string[] imports, object args)
            => Run<bool>(code + ";return true;", imports, args);
    }
}

... when I call it with a large business object my app just crashes with the system event log having an event saying ...

Faulting application name: My.exe, version: 1.0.0.0, time stamp: 0x5e597f86
Faulting module name: coreclr.dll, version: 4.700.20.11803, time stamp: 0x5e4c6185
Exception code: 0xc00000fd
Fault offset: 0x0000000000231774
Faulting process id: 0xfb4
Faulting application start time: 0x01d612424b37cc95
Faulting application path: D:\My Project\My.exe
Faulting module path: D:\My Project\coreclr.dll
Report Id: aa6c531d-dbdb-4f30-bfe1-ab341f9ebc08
Faulting package full name: 
Faulting package-relative application ID: 

Is there a way to handle large ram allocations (say up to 4GB) inside a Roslyn script and avoid this behaviour (like setting a static flag or something)?

The issue seems to be implied as being a stack overflow from other posts on here like this one ... How handle Application Error Exception code: 0xc00000fd

... I believe the cause is that the "large object" in my case is an array of approx 10,000 items I want to loop through and run some basic code e.g. transforming it. There's no chance i'm running in to say ... deep recursion issues that never end (typically what I might expect for a standard stack overflow) since my set is finite.

It seems to just crash in coreclr.dll in the event that I ask it to loop through a large set without even trying. The large set i'm using to test is a CSV file of approx 10k rows, about 2 to 3MB of data which will grow in ram during processing but nothing that modern computers can't handle with ease, i's not like i'm asking it to iterate over sets of billions of rows.

c#
.net-core
scripting
roslyn
asked on Stack Overflow Apr 14, 2020 by War • edited Apr 14, 2020 by War

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0