@@ -2429,7 +2429,6 @@ emit_missing_method_error (MonoMethodBuilder *mb, MonoError *failure, const char
2429
2429
static void
2430
2430
emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder * mb , MonoMethod * accessor_method , MonoMethodSignature * sig , MonoGenericContext * ctx , MonoUnsafeAccessorKind kind , const char * member_name )
2431
2431
{
2432
- // TODO: support coreCLR's weird "you can call the .ctor as a normal instance member" method
2433
2432
g_assert (kind == MONO_UNSAFE_ACCESSOR_CTOR );
2434
2433
// null or empty string member name is ok for a constructor
2435
2434
if (!member_name || member_name [0 ] == '\0' )
@@ -2473,6 +2472,9 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
2473
2472
g_assert (kind == MONO_UNSAFE_ACCESSOR_METHOD || kind == MONO_UNSAFE_ACCESSOR_STATIC_METHOD );
2474
2473
g_assert (member_name != NULL );
2475
2474
2475
+ // We explicitly allow calling a constructor as if it was an instance method, but we need some hacks in a couple of places
2476
+ gboolean ctor_as_method = !strcmp (member_name , ".ctor" );
2477
+
2476
2478
if (sig -> param_count < 1 || sig -> params [0 ] == NULL || unsafe_accessor_target_type_forbidden (sig -> params [0 ])) {
2477
2479
mono_mb_emit_exception_full (mb , "System" , "BadImageFormatException" , "Invalid usage of UnsafeAccessorAttribute." );
2478
2480
return ;
@@ -2491,7 +2493,11 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
2491
2493
2492
2494
ERROR_DECL (find_method_error );
2493
2495
MonoClass * in_class = mono_class_is_ginst (target_class ) ? mono_class_get_generic_class (target_class )-> container_class : target_class ;
2494
- MonoMethod * target_method = mono_unsafe_accessor_find_method (in_class , member_name , member_sig , target_class , find_method_error );
2496
+ MonoMethod * target_method = NULL ;
2497
+ if (!ctor_as_method )
2498
+ target_method = mono_unsafe_accessor_find_method (in_class , member_name , member_sig , target_class , find_method_error );
2499
+ else
2500
+ target_method = mono_unsafe_accessor_find_ctor (in_class , member_sig , target_class , find_method_error );
2495
2501
if (!is_ok (find_method_error ) || target_method == NULL ) {
2496
2502
// g_warning ("FAILed to find '%s' in '%s' with sig '%s', due to %s\n", member_name, m_class_get_name (target_class), mono_signature_full_name (member_sig), mono_error_get_message (find_method_error));
2497
2503
emit_missing_method_error (mb , find_method_error , member_name );
0 commit comments