From 8f461884c967be466cbfa2457fd982835f66b730 Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Wed, 9 Sep 2020 13:33:47 -0700 Subject: [PATCH] Update JSCallResultTypeHelper.cs (#25628) * Update JSCallResultTypeHelper.cs and PublicAPI.Unshipped.txt * CR feedback. * Removed exception message --- .../JSInterop/JSCallResultTypeHelper.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Shared/JSInterop/JSCallResultTypeHelper.cs b/src/Shared/JSInterop/JSCallResultTypeHelper.cs index 82c3920c72..8bf1a547fc 100644 --- a/src/Shared/JSInterop/JSCallResultTypeHelper.cs +++ b/src/Shared/JSInterop/JSCallResultTypeHelper.cs @@ -1,15 +1,28 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Reflection; + namespace Microsoft.JSInterop { internal static class JSCallResultTypeHelper { + // We avoid using Assembly.GetExecutingAssembly() because this is shared code. + private static readonly Assembly _currentAssembly = typeof(JSCallResultType).Assembly; + public static JSCallResultType FromGeneric() - => typeof(TResult) == typeof(IJSObjectReference) - || typeof(TResult) == typeof(IJSInProcessObjectReference) - || typeof(TResult) == typeof(IJSUnmarshalledObjectReference) ? - JSCallResultType.JSObjectReference : - JSCallResultType.Default; + { + if (typeof(TResult).Assembly == _currentAssembly + && (typeof(TResult) == typeof(IJSObjectReference) + || typeof(TResult) == typeof(IJSInProcessObjectReference) + || typeof(TResult) == typeof(IJSUnmarshalledObjectReference))) + { + return JSCallResultType.JSObjectReference; + } + else + { + return JSCallResultType.Default; + } + } } }