diff --git a/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts b/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
index 4b5d409d0f..5386b92bb5 100644
--- a/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
+++ b/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
@@ -264,17 +264,14 @@ module DotNet {
}
public serializeAsArg() {
- return `__dotNetObject:${this._id}`;
+ return {__dotNetObject: this._id};
}
}
- const dotNetObjectValueFormat = /^__dotNetObject\:(\d+)$/;
+ const dotNetObjectRefKey = '__dotNetObject';
attachReviver(function reviveDotNetObject(key: any, value: any) {
- if (typeof value === 'string') {
- const match = value.match(dotNetObjectValueFormat);
- if (match) {
- return new DotNetObject(parseInt(match[1]));
- }
+ if (value && typeof value === 'object' && value.hasOwnProperty(dotNetObjectRefKey)) {
+ return new DotNetObject(value.__dotNetObject);
}
// Unrecognized - let another reviver handle it
diff --git a/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.csproj b/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.csproj
index 87fd913427..5f83c53091 100644
--- a/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.csproj
+++ b/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.csproj
@@ -5,6 +5,6 @@
-
+
diff --git a/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.netstandard2.0.cs b/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.netstandard2.0.cs
index 95b9b7956c..1db3385bd7 100644
--- a/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.netstandard2.0.cs
+++ b/src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.netstandard2.0.cs
@@ -12,12 +12,19 @@ namespace Microsoft.JSInterop
[Microsoft.JSInterop.JSInvokableAttribute("DotNetDispatcher.ReleaseDotNetObject")]
public static void ReleaseDotNetObject(long dotNetObjectId) { }
}
- public partial class DotNetObjectRef : System.IDisposable
+ public static partial class DotNetObjectRef
{
- public DotNetObjectRef(object value) { }
- public object Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public static Microsoft.JSInterop.DotNetObjectRef Create(TValue value) where TValue : class { throw null; }
+ }
+ public sealed partial class DotNetObjectRef : System.IDisposable where TValue : class
+ {
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
+ public DotNetObjectRef() { }
+ [System.Text.Json.Serialization.JsonIgnoreAttribute]
+ public TValue Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
+ public long __dotNetObject { get { throw null; } set { } }
public void Dispose() { }
- public void EnsureAttachedToJsRuntime(Microsoft.JSInterop.IJSRuntime runtime) { }
}
public partial interface IJSInProcessRuntime : Microsoft.JSInterop.IJSRuntime
{
@@ -25,8 +32,7 @@ namespace Microsoft.JSInterop
}
public partial interface IJSRuntime
{
- System.Threading.Tasks.Task InvokeAsync(string identifier, params object[] args);
- void UntrackObjectRef(Microsoft.JSInterop.DotNetObjectRef dotNetObjectRef);
+ System.Threading.Tasks.Task InvokeAsync(string identifier, params object[] args);
}
public partial class JSException : System.Exception
{
@@ -36,7 +42,7 @@ namespace Microsoft.JSInterop
{
protected JSInProcessRuntimeBase() { }
protected abstract string InvokeJS(string identifier, string argsJson);
- public T Invoke(string identifier, params object[] args) { throw null; }
+ public TValue Invoke(string identifier, params object[] args) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=true)]
public partial class JSInvokableAttribute : System.Attribute
@@ -45,30 +51,21 @@ namespace Microsoft.JSInterop
public JSInvokableAttribute(string identifier) { }
public string Identifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
}
- public static partial class Json
- {
- public static T Deserialize(string json) { throw null; }
- public static string Serialize(object value) { throw null; }
- }
public static partial class JSRuntime
{
public static void SetCurrentJSRuntime(Microsoft.JSInterop.IJSRuntime instance) { }
}
public abstract partial class JSRuntimeBase : Microsoft.JSInterop.IJSRuntime
{
- public JSRuntimeBase() { }
+ protected JSRuntimeBase() { }
protected abstract void BeginInvokeJS(long asyncHandle, string identifier, string argsJson);
public System.Threading.Tasks.Task InvokeAsync(string identifier, params object[] args) { throw null; }
- public void UntrackObjectRef(Microsoft.JSInterop.DotNetObjectRef dotNetObjectRef) { }
}
}
namespace Microsoft.JSInterop.Internal
{
- public partial interface ICustomArgSerializer
- {
- object ToJsonPrimitive();
- }
- public partial class JSAsyncCallResult
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
+ public sealed partial class JSAsyncCallResult
{
internal JSAsyncCallResult() { }
}
diff --git a/src/JSInterop/Microsoft.JSInterop/src/DotNetDispatcher.cs b/src/JSInterop/Microsoft.JSInterop/src/DotNetDispatcher.cs
index d6c83d512d..5ecd3506e0 100644
--- a/src/JSInterop/Microsoft.JSInterop/src/DotNetDispatcher.cs
+++ b/src/JSInterop/Microsoft.JSInterop/src/DotNetDispatcher.cs
@@ -1,14 +1,16 @@
// 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 Microsoft.JSInterop.Internal;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using System.Threading.Tasks;
+using Microsoft.JSInterop.Internal;
namespace Microsoft.JSInterop
{
@@ -17,8 +19,10 @@ namespace Microsoft.JSInterop
///
public static class DotNetDispatcher
{
- private static ConcurrentDictionary> _cachedMethodsByAssembly
- = new ConcurrentDictionary>();
+ internal const string DotNetObjectRefKey = nameof(DotNetObjectRef