From 04d0608e606d3afb0c667761806b2bec972c2743 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 Jul 2026 22:02:53 -0500 Subject: [PATCH 1/3] Preload assembly for dynamic support in editor --- Source/Engine/Engine/NativeInterop.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Engine/Engine/NativeInterop.cs b/Source/Engine/Engine/NativeInterop.cs index 304270b34..d6d7e26d9 100644 --- a/Source/Engine/Engine/NativeInterop.cs +++ b/Source/Engine/Engine/NativeInterop.cs @@ -1758,6 +1758,9 @@ namespace FlaxEngine.Interop assembly.GetType("System.Linq.Expressions.Compiler.DelegateHelpers") .GetMethod("MakeNewCustomDelegate", BindingFlags.NonPublic | BindingFlags.Static).CreateDelegate>(); + // Load Microsoft.CSharp assembly into collectible ALC for dynamic binder support + scriptingAssemblyLoadContext.LoadFromAssemblyPath(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location); + // Create dummy delegates to force the dynamic Snippets assembly to be loaded in correcet ALCs MakeNewCustomDelegateFunc(new[] { typeof(void) }); { From b0ba936ebefb4d4ec95bdc13eb43824a99026589 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 Jul 2026 22:12:05 -0500 Subject: [PATCH 2/3] Move to better method location. --- Source/Engine/Engine/NativeInterop.Unmanaged.cs | 5 +++++ Source/Engine/Engine/NativeInterop.cs | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index 33e102089..7decdcffc 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -1011,6 +1011,11 @@ namespace FlaxEngine.Interop scriptingAssemblyLoadContext = new AssemblyLoadContext("Flax", isCollectible: false); #endif DelegateHelpers.InitMethods(); + +#if FLAX_EDITOR + // Load Microsoft.CSharp assembly into collectible ALC for dynamic binder support + scriptingAssemblyLoadContext.LoadFromAssemblyPath(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location); +#endif } [UnmanagedCallersOnly] diff --git a/Source/Engine/Engine/NativeInterop.cs b/Source/Engine/Engine/NativeInterop.cs index d6d7e26d9..304270b34 100644 --- a/Source/Engine/Engine/NativeInterop.cs +++ b/Source/Engine/Engine/NativeInterop.cs @@ -1758,9 +1758,6 @@ namespace FlaxEngine.Interop assembly.GetType("System.Linq.Expressions.Compiler.DelegateHelpers") .GetMethod("MakeNewCustomDelegate", BindingFlags.NonPublic | BindingFlags.Static).CreateDelegate>(); - // Load Microsoft.CSharp assembly into collectible ALC for dynamic binder support - scriptingAssemblyLoadContext.LoadFromAssemblyPath(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location); - // Create dummy delegates to force the dynamic Snippets assembly to be loaded in correcet ALCs MakeNewCustomDelegateFunc(new[] { typeof(void) }); { From a319bdfc90d801512d80ef6299479496d8a8e6fb Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 Jul 2026 22:14:01 -0500 Subject: [PATCH 3/3] Simplify location. --- Source/Engine/Engine/NativeInterop.Unmanaged.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index 7decdcffc..cb8688dcf 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -1007,15 +1007,13 @@ namespace FlaxEngine.Interop scriptingAssemblyLoadContext = new AssemblyLoadContext("Flax", isCollectible: true); scriptingAssemblyLoadContext.Resolving += OnScriptingAssemblyLoadContextResolving; + + // Load Microsoft.CSharp assembly into collectible ALC for dynamic binder support + scriptingAssemblyLoadContext.LoadFromAssemblyPath(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location); #else scriptingAssemblyLoadContext = new AssemblyLoadContext("Flax", isCollectible: false); #endif DelegateHelpers.InitMethods(); - -#if FLAX_EDITOR - // Load Microsoft.CSharp assembly into collectible ALC for dynamic binder support - scriptingAssemblyLoadContext.LoadFromAssemblyPath(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location); -#endif } [UnmanagedCallersOnly]