@@ -257,7 +257,7 @@ internal static Type CreateDerivedType(string name,
257
257
Type . EmptyTypes ) ;
258
258
ILGenerator il = methodBuilder . GetILGenerator ( ) ;
259
259
il . Emit ( OpCodes . Ldarg_0 ) ;
260
- il . Emit ( OpCodes . Call , typeof ( PythonDerivedType ) . GetMethod ( " Finalize" ) ) ;
260
+ il . Emit ( OpCodes . Call , typeof ( PythonDerivedType ) . GetMethod ( nameof ( PythonDerivedType . Finalize ) ) ) ;
261
261
il . Emit ( OpCodes . Ldarg_0 ) ;
262
262
il . Emit ( OpCodes . Call , baseClass . GetMethod ( "Finalize" , BindingFlags . NonPublic | BindingFlags . Instance ) ) ;
263
263
il . Emit ( OpCodes . Ret ) ;
@@ -775,8 +775,8 @@ public static T InvokeGetProperty<T>(IPythonDerivedType obj, string propertyName
775
775
Runtime . XIncref ( self . pyHandle ) ;
776
776
using var pyself = new PyObject ( self . pyHandle ) ;
777
777
PyObject pyvalue = pyself . GetAttr ( propertyName ) ;
778
- return ( T ) pyvalue . AsManagedObject ( typeof ( T ) ) ;
779
- }
778
+ return ( T ) pyvalue . AsManagedObject ( typeof ( T ) ) ;
779
+ }
780
780
finally
781
781
{
782
782
Runtime . PyGILState_Release ( gs ) ;
@@ -886,7 +886,7 @@ public static void Finalize(IPythonDerivedType obj)
886
886
Runtime . XDecref ( dict ) ;
887
887
}
888
888
Runtime . PyObject_GC_Del ( self . pyHandle ) ;
889
- self . gcHandle . Free ( ) ;
889
+ if ( self . gcHandle . IsAllocated ) self . gcHandle . Free ( ) ;
890
890
}
891
891
finally
892
892
{