diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 545cd683..0d420440 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -206,7 +206,9 @@ namespace CppSharp.Generators.CSharp string instance = Context.ReturnVarName; if (ctx.Kind == CSharpMarshalKind.NativeField) { - instance = string.Format("new global::System.IntPtr(&{0})", instance); + Context.SupportBefore.WriteLine( + "var __copy = new global::System.IntPtr(&{0});", instance); + instance = "__copy"; } if (@class.IsRefType)