From ba5d74338545c4a031c25940ed5b9a537b2fb08e Mon Sep 17 00:00:00 2001 From: jbtule Date: Mon, 18 Sep 2017 15:38:13 -0500 Subject: [PATCH] Make sure type load error is caught, even when unexpected fixes #21 --- Dynamitey.sln.DotSettings | 1 + Dynamitey/Dynamic.cs | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Dynamitey.sln.DotSettings b/Dynamitey.sln.DotSettings index 11f2c26..e544afe 100644 --- a/Dynamitey.sln.DotSettings +++ b/Dynamitey.sln.DotSettings @@ -1,3 +1,4 @@  + SL <data><IncludeFilters /><ExcludeFilters /></data> <data /> \ No newline at end of file diff --git a/Dynamitey/Dynamic.cs b/Dynamitey/Dynamic.cs index b607ebd..a02d88c 100644 --- a/Dynamitey/Dynamic.cs +++ b/Dynamitey/Dynamic.cs @@ -47,21 +47,40 @@ public static void ClearCaches() InvokeHelper.ClearAllCaches(); } - private static readonly Type ComObjectType; + + + private static readonly dynamic ComBinder + = new DynamicObjects.LateType("System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + + + internal static readonly dynamic Impromptu + = new DynamicObjects.LateType("ImpromptuInterface.Impromptu, ImpromptuInterface, PublicKeyToken=0b1781c923b2975b"); + + internal static readonly dynamic TypeDescriptor + = new DynamicObjects.LateType("System.ComponentModel.TypeDescriptor, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + - private static readonly dynamic ComBinder; + private static readonly Type ComObjectType; + internal static readonly Type TypeConverterAttributeSL; static Dynamic() { try { ComObjectType = typeof(object).GetTypeInfo().Assembly.GetType("System.__ComObject"); - ComBinder = new DynamicObjects.LateType( - "System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); } catch { - + ComObjectType = null; + } + try + { + TypeConverterAttributeSL + = Type.GetType("System.ComponentModel.TypeConverter, System, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", false); + } + catch + { + TypeConverterAttributeSL = null; } } /// @@ -796,15 +815,6 @@ public static IEnumerable ConvertAll(this System.Collections.IEnumerable e return enumerable.Cast().Select(it => InvokeConvert(it, typeof (T), explict)).Cast(); } - internal static readonly dynamic Impromptu - = new DynamicObjects.LateType("ImpromptuInterface.Impromptu, ImpromptuInterface, PublicKeyToken=0b1781c923b2975b"); - - internal static readonly dynamic TypeDescriptor - = new DynamicObjects.LateType("System.ComponentModel.TypeDescriptor, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - - internal static readonly Type TypeConverterAttributeSL - = Type.GetType("System.ComponentModel.TypeConverter, System, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", false); - /// /// Goes the extra mile to convert target to type. ///