From 7b0dca42ce524da4075563a055a9b4be967350c1 Mon Sep 17 00:00:00 2001 From: Lewis Jordan Date: Thu, 7 Sep 2023 16:00:46 +0100 Subject: [PATCH] Added MonoPInvokeCallback to methods that will be called from unmanaged code --- src/Generator/Generators/CSharp/CSharpSources.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 3ee9104b1..cdd5fc210 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2097,7 +2097,9 @@ private void GenerateVTableMethodDelegates(Class @class, Method method) WriteLine($"private static {method.FunctionType} {vTableMethodDelegateName}Instance;"); NewLine(); - + WriteLine("#if ENABLE_IL2CPP"); + WriteLine($"[AOT.MonoPInvokeCallback(typeof({method.FunctionType}))]"); + WriteLine("#endif"); using (WriteBlock($"private static {retType} {vTableMethodDelegateName}Hook({string.Join(", ", @params)})")) { WriteLine($@"var {Helpers.TargetIdentifier} = {@class.Visit(TypePrinter)}.__GetInstance({Helpers.InstanceField});");