2009-11-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Nov 2009 21:13:15 +0000 (21:13 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Nov 2009 21:13:15 +0000 (21:13 -0000)
* class.c: When CoreCLR is enabled don't call mono_init_com_types
if MONO_CLASS_IS_IMPORT return true unless the type reside in
platform (trusted) code. Instead we return a TypeLoadException to
be thrown later. This is the exception thrown by Silverlight 2 if
a type, inside application (user) code is marked with [ComImport]

svn path=/trunk/mono/; revision=145534

mono/metadata/ChangeLog
mono/metadata/class.c

index 11ab00f0a1b32e8bc688fb78bb8f6dbddf7466b3..1a501e6f8cd5885572b218b2e7bb3440b26bb63a 100644 (file)
@@ -1,3 +1,11 @@
+2009-11-05  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * class.c: When CoreCLR is enabled don't call mono_init_com_types
+       if MONO_CLASS_IS_IMPORT return true unless the type reside in 
+       platform (trusted) code. Instead we return a TypeLoadException to
+       be thrown later. This is the exception thrown by Silverlight 2 if
+       a type, inside application (user) code is marked with [ComImport]
+
 2009-11-05  Zoltan Varga  <vargaz@gmail.com>
 
        * icall.c (ves_icall_System_Diagnostics_Debugger_IsAttached_internal): Call
index c1fcf6d3099d435365dadc53d1ed9c23f78081b2..5d4cd36d5ede876064bccc2d7f59e099727d565b 100644 (file)
@@ -4283,6 +4283,30 @@ mono_class_setup_mono_type (MonoClass *class)
 
 }
 
+/*
+ * COM initialization (using mono_init_com_types) is delayed until needed. 
+ * However when a [ComImport] attribute is present on a type it will trigger
+ * the initialization. This is not a problem unless the BCL being executed 
+ * lacks the types that COM depends on (e.g. Variant on Silverlight).
+ */
+static void
+init_com_from_comimport (MonoClass *class)
+{
+       /* we don't always allow COM initialization under the CoreCLR (e.g. Moonlight does not require it) */
+       if ((mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR)) {
+               /* but some other CoreCLR user could requires it for their platform (i.e. trusted) code */
+               if (!mono_security_core_clr_determine_platform_image (class->image)) {
+                       /* but it can not be made available for application (i.e. user code) since all COM calls
+                        * are considered native calls. In this case we fail with a TypeLoadException (just like
+                        * Silverlight 2 does */
+                       mono_class_set_failure (class, MONO_EXCEPTION_TYPE_LOAD, NULL);
+                       return;
+               }
+       }
+       /* FIXME : we should add an extra checks to ensure COM can be initialized properly before continuing */
+       mono_init_com_types ();
+}
+
 /*
  * LOCKING: this assumes the loader lock is held
  */
@@ -4309,7 +4333,7 @@ mono_class_setup_parent (MonoClass *class, MonoClass *parent)
        if (!MONO_CLASS_IS_INTERFACE (class)) {
                /* Imported COM Objects always derive from __ComObject. */
                if (MONO_CLASS_IS_IMPORT (class)) {
-                       mono_init_com_types ();
+                       init_com_from_comimport (class);
                        if (parent == mono_defaults.object_class)
                                parent = mono_defaults.com_object_class;
                }
@@ -4360,7 +4384,7 @@ mono_class_setup_parent (MonoClass *class, MonoClass *parent)
        } else {
                /* initialize com types if COM interfaces are present */
                if (MONO_CLASS_IS_IMPORT (class))
-                       mono_init_com_types ();
+                       init_com_from_comimport (class);
                class->parent = NULL;
        }