# ScriptRun.Compile() Out of Memory

**URL:** https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442
**Category:** AlterNET Studio Support
**Tags:** scripter
**Created:** [December 20, 2023, 1:23am UTC](https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442 "2023-12-20T01:23:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rhoward](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/r/606060/32.png) [@rhoward](https://forum.alternetsoft.com/u/rhoward)
#### Post date: [December 20, 2023, 1:23am UTC](https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442/1 "2023-12-20T01:23:15Z")

</div>

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()?

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [December 22, 2023, 12:52am UTC](https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442/2 "2023-12-22T00:52:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Emi](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/e/606060/32.png) [@Emi](https://forum.alternetsoft.com/u/Emi)
#### Post date: [August 26, 2025, 10:46am UTC](https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442/3 "2025-08-26T10:46:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [August 28, 2025, 6:36am UTC](https://forum.alternetsoft.com/t/scriptrun-compile-out-of-memory/442/4 "2025-08-28T06:36:08Z")

</div>

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`.
