diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index a29ae23a..707f2477 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -325,8 +325,8 @@ namespace CppSharp.Generators.CSharp var dtor = originalClass.Destructors.FirstOrDefault(); if (dtor != null && dtor.IsVirtual) { - Context.SupportBefore.WriteLine("else {0}.NativeToManagedMap[{1}] = {2} = {3}.{4}({1});", - qualifiedClass, Context.ReturnVarName, ret, type, + Context.SupportBefore.WriteLine("else {0}.NativeToManagedMap[{1}] = {2} = ({3}) {4}.{5}({1});", + qualifiedClass, Context.ReturnVarName, ret, QualifiedIdentifier(@class), type, Helpers.CreateInstanceIdentifier, Context.ReturnVarName); } else