@@ -21,8 +21,11 @@ namespace Python.Runtime {
21
21
//========================================================================
22
22
23
23
internal class ConstructorBinder : MethodBinder {
24
+ private Type _containingType = null ;
24
25
25
- internal ConstructorBinder ( ) : base ( ) { }
26
+ internal ConstructorBinder ( Type containingType ) : base ( ) {
27
+ _containingType = containingType ;
28
+ }
26
29
27
30
//====================================================================
28
31
// Constructors get invoked when an instance of a wrapped managed
@@ -53,9 +56,31 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw) {
53
56
/// </remarks>
54
57
internal object InvokeRaw ( IntPtr inst , IntPtr args , IntPtr kw ,
55
58
MethodBase info ) {
56
- Binding binding = this . Bind ( inst , args , kw , info ) ;
57
59
Object result ;
58
60
61
+ if ( _containingType . IsValueType && ! _containingType . IsPrimitive &&
62
+ ! _containingType . IsEnum && _containingType != typeof ( decimal ) &&
63
+ Runtime . PyTuple_Size ( args ) == 0 ) {
64
+ // If you are trying to construct an instance of a struct by
65
+ // calling its default constructor, that ConstructorInfo
66
+ // instance will not appear in reflection and the object must
67
+ // instead be constructed via a call to
68
+ // Activator.CreateInstance().
69
+ try {
70
+ result = Activator . CreateInstance ( _containingType ) ;
71
+ }
72
+ catch ( Exception e ) {
73
+ if ( e . InnerException != null ) {
74
+ e = e . InnerException ;
75
+ }
76
+ Exceptions . SetError ( e ) ;
77
+ return null ;
78
+ }
79
+ return result ;
80
+ }
81
+
82
+ Binding binding = this . Bind ( inst , args , kw , info ) ;
83
+
59
84
if ( binding == null ) {
60
85
// It is possible for __new__ to be invoked on construction
61
86
// of a Python subclass of a managed class, so args may
0 commit comments