@@ -21,8 +21,11 @@ namespace Python.Runtime {
2121 //========================================================================
2222
2323 internal class ConstructorBinder : MethodBinder {
24+ private Type _containingType = null ;
2425
25- internal ConstructorBinder ( ) : base ( ) { }
26+ internal ConstructorBinder ( Type containingType ) : base ( ) {
27+ _containingType = containingType ;
28+ }
2629
2730 //====================================================================
2831 // Constructors get invoked when an instance of a wrapped managed
@@ -53,9 +56,31 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw) {
5356 /// </remarks>
5457 internal object InvokeRaw ( IntPtr inst , IntPtr args , IntPtr kw ,
5558 MethodBase info ) {
56- Binding binding = this . Bind ( inst , args , kw , info ) ;
5759 Object result ;
5860
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+
5984 if ( binding == null ) {
6085 // It is possible for __new__ to be invoked on construction
6186 // of a Python subclass of a managed class, so args may
0 commit comments