diff --git a/WinRT.Runtime/ComWrappersSupport.cs b/WinRT.Runtime/ComWrappersSupport.cs index 53242c133..31b5b75b3 100644 --- a/WinRT.Runtime/ComWrappersSupport.cs +++ b/WinRT.Runtime/ComWrappersSupport.cs @@ -267,6 +267,11 @@ private static Func CreateArrayFactory(Type implementation internal static Func CreateTypedRcwFactory(string runtimeClassName) { + // If we don't have a runtime class name, then we just use IInspectable. + if (string.IsNullOrEmpty(runtimeClassName)) + { + return (IInspectable obj) => obj; + } // PropertySet and ValueSet can return IReference but Nullable is illegal if (runtimeClassName == "Windows.Foundation.IReference`1") { @@ -277,7 +282,18 @@ internal static Func CreateTypedRcwFactory(string runtimeC return (IInspectable obj) => new ABI.System.Nullable(obj.ObjRef); } - var (implementationType, _) = TypeNameSupport.FindTypeByName(runtimeClassName.AsSpan()); + Type implementationType = null; + + try + { + (implementationType, _) = TypeNameSupport.FindTypeByName(runtimeClassName.AsSpan()); + } + catch (TypeLoadException) + { + // If we reach here, then we couldn't find a type that matches the runtime class name. + // Fall back to using IInspectable directly. + return (IInspectable obj) => obj; + } if (implementationType.IsGenericType && implementationType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<,>)) { diff --git a/WinUI/WinUIDesktopSample/App.xaml.cs b/WinUI/WinUIDesktopSample/App.xaml.cs index f6ac2bf22..62e05f6ae 100644 --- a/WinUI/WinUIDesktopSample/App.xaml.cs +++ b/WinUI/WinUIDesktopSample/App.xaml.cs @@ -22,6 +22,7 @@ public App() Window myWindow; protected override void OnLaunched(LaunchActivatedEventArgs args) { + var value = DependencyProperty.UnsetValue; var button = new Button { Content = "Click me to load MainPage",