From 5b1a7c25b35593d3c81d69410bd266797b92f11f Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 5 Sep 2023 04:35:01 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20KeyValuePair=20in=20marsh?= =?UTF-8?q?aling=20because=20it=E2=80=99s=20overloaded=20on=20UWP=20(#3435?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + Realm/Realm/Native/HttpClientTransport.cs | 8 ++-- Realm/Realm/Native/MarshaledPair.cs | 45 +++++++++++++++++++++++ Realm/Realm/Native/SyncError.cs | 2 +- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Realm/Realm/Native/MarshaledPair.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ea260497..3d262b9873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed * Fixed the message of the `MissingMemberException` being thrown when attempting to access a non-existent property with the dynamic API. (PR [#3432](https://github.com/realm/realm-dotnet/pull/3432)) +* Fixed a `Cannot marshal generic Windows Runtime types with a non Windows Runtime type as a generic type argument` build error when using .NET Native. (Issue [#3434](https://github.com/realm/realm-dotnet/issues/3434), since 11.4.0) ### Compatibility * Realm Studio: 13.0.0 or later. diff --git a/Realm/Realm/Native/HttpClientTransport.cs b/Realm/Realm/Native/HttpClientTransport.cs index 91f0ee7c4a..c435dbd915 100644 --- a/Realm/Realm/Native/HttpClientTransport.cs +++ b/Realm/Realm/Native/HttpClientTransport.cs @@ -59,7 +59,7 @@ private readonly struct HttpClientRequest public readonly UInt64 timeout_ms; - public readonly MarshaledVector> headers; + public readonly MarshaledVector> headers; private readonly StringValue body; @@ -91,7 +91,7 @@ private struct HttpClientResponse public CustomErrorCode custom_status_code; - public MarshaledVector> headers; + public MarshaledVector> headers; public StringValue body; } @@ -148,13 +148,13 @@ private static async void ExecuteRequest(HttpClientRequest request, IntPtr callb var response = await httpClient.SendAsync(message, cts.Token).ConfigureAwait(false); var headers = response.Headers.Concat(response.Content.Headers) - .Select(h => new KeyValuePair(StringValue.AllocateFrom(h.Key, arena), StringValue.AllocateFrom(h.Value.FirstOrDefault(), arena))) + .Select(h => new MarshaledPair(StringValue.AllocateFrom(h.Key, arena), StringValue.AllocateFrom(h.Value.FirstOrDefault(), arena))) .ToArray(); var nativeResponse = new HttpClientResponse { http_status_code = (int)response.StatusCode, - headers = MarshaledVector>.AllocateFrom(headers, arena), + headers = MarshaledVector>.AllocateFrom(headers, arena), body = StringValue.AllocateFrom(await response.Content.ReadAsStringAsync().ConfigureAwait(false), arena), }; diff --git a/Realm/Realm/Native/MarshaledPair.cs b/Realm/Realm/Native/MarshaledPair.cs new file mode 100644 index 0000000000..babfc46b0a --- /dev/null +++ b/Realm/Realm/Native/MarshaledPair.cs @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +using System.Collections.Generic; + +namespace Realms.Native +{ + internal struct MarshaledPair + where TKey : unmanaged + where TValue : unmanaged + { + public TKey Key; + + public TValue Value; + + public MarshaledPair(TKey key, TValue value) + { + Key = key; + Value = value; + } + + public void Deconstruct(out TKey key, out TValue value) + { + key = Key; + value = Value; + } + + public static implicit operator KeyValuePair(MarshaledPair pair) => new (pair.Key, pair.Value); + } +} diff --git a/Realm/Realm/Native/SyncError.cs b/Realm/Realm/Native/SyncError.cs index 6e45cdb794..09ecae53a5 100644 --- a/Realm/Realm/Native/SyncError.cs +++ b/Realm/Realm/Native/SyncError.cs @@ -34,7 +34,7 @@ internal struct SyncError [MarshalAs(UnmanagedType.U1)] public bool is_client_reset; - public MarshaledVector> user_info_pairs; + public MarshaledVector> user_info_pairs; public MarshaledVector compensating_writes;