ScriptRun.Compile() Out of Memory

Calling ScriptRun.Compile() reloads a huge number of assemblies on every call. I would have thought it would load assemblies on the first call only. Also, I’m not sure why its loading all these assemblies when my script does not need them.

How does it decide what assemblies to load during Compile()?

Hi Rich,

Just wanted to confirm if you’re using Scripter under .NET Core?

By default, we load SDK references in case you compile SDK/.NET Core projects, however, these assemblies are only loaded during project compilation as metadata references.

If you could send us a sample project where you’re experiencing this problem we will be able to look further at it.

Kind regards,
Dmitry

Hello currently facing the same issue, I was wondering if there is a fix for this?

In version 10 of Alternet.Studio, the Alternet.Scripter.ScriptHost class includes both a static property DefaultResolveRecursiveReferences and an instance property ResolveRecursiveReferences.

If either of these is set to false, references will not be resolved recursively, and the scripter will only use the references explicitly added in your code.

If you want to minimize the number of references, avoid calling ScriptSource.WithDefaultReferences() — especially without parameters — as it adds all .NET libraries by default.

A minimal set of references includes:

  • "mscorlib.dll"
  • "System"
  • "System.Runtime"
  • "VisualBasic.Core.dll" (required for VB scripting)
  • "VisualBasic.dll" (required for VB scripting)

In the latest builds, we’ve added two helpful methods: ScriptSource.WithMinimalReferences() and ScriptSource.WithSystemReferences().

You can use ScriptSource.WithMinimalReferences() and then manually add any additional references your script requires using ScriptSource.References.Add.