Skip to content

Commit 65cdcfc

Browse files
committed
Fix IMissingServiceDiagnosticsService descriptor and ServiceMoniker serialization
The descriptor for `IMissingServiceDiagnosticsService` was evidently always broken, because is used MessagePack-CSharp and `MissingServiceAnalysis` was not annotated with `[MessagePackObject]`. The fix then is to just switch to Nerdbank.MessagePack, which doesn't require the attributes. Also `ServiceMoniker` was dropping its `Version` property when serialized with Nerdbank.MessagePack on account of PolyType not seeing the constructor that could initialize the property.
1 parent 0ee1a15 commit 65cdcfc

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

src/Microsoft.ServiceHub.Framework/Container/GlobalBrokeredServiceContainer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Nerdbank.Streams;
1212
using Newtonsoft.Json;
1313
using Newtonsoft.Json.Linq;
14+
using StreamJsonRpc;
1415

1516
namespace Microsoft.VisualStudio.Utilities.ServiceBroker;
1617

@@ -99,10 +100,12 @@ protected GlobalBrokeredServiceContainer(ImmutableDictionary<ServiceMoniker, Ser
99100
/// Gets a descriptor for the service that can diagnose the cause of a missing brokered service.
100101
/// Use <see cref="IMissingServiceDiagnosticsService"/> to interact with this service.
101102
/// </summary>
102-
public static ServiceRpcDescriptor MissingServiceDiagnostics { get; } = new ServiceJsonRpcDescriptor(
103+
public static ServiceRpcDescriptor MissingServiceDiagnostics { get; } = new ServiceJsonRpcPolyTypeDescriptor(
103104
new ServiceMoniker("Microsoft.VisualStudio.GlobalBrokeredServiceContainer.MissingServiceDiagnostics", new Version(1, 0)),
104-
ServiceJsonRpcDescriptor.Formatters.MessagePack,
105-
ServiceJsonRpcDescriptor.MessageDelimiters.BigEndianInt32LengthHeader);
105+
ServiceJsonRpcPolyTypeDescriptor.Formatters.NerdbankMessagePack,
106+
ServiceJsonRpcPolyTypeDescriptor.MessageDelimiters.BigEndianInt32LengthHeader,
107+
PolyType.SourceGenerator.TypeShapeProvider_Microsoft_ServiceHub_Framework.Default)
108+
.WithRpcTargetMetadata(RpcTargetMetadata.FromShape(PolyType.SourceGenerator.TypeShapeProvider_Microsoft_ServiceHub_Framework.Default.IMissingServiceDiagnosticsService));
106109

107110
/// <inheritdoc />
108111
public abstract IReadOnlyDictionary<string, string> LocalUserCredentials { get; }

src/Microsoft.ServiceHub.Framework/Container/MissingServiceAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class MissingServiceAnalysis
1515
/// </summary>
1616
/// <param name="errorCode">The error code explaining why the service could not be obtained.</param>
1717
/// <param name="expectedSource">The source that the service was expected to come from.</param>
18-
internal MissingServiceAnalysis(MissingBrokeredServiceErrorCode errorCode, ServiceSource? expectedSource)
18+
public MissingServiceAnalysis(MissingBrokeredServiceErrorCode errorCode, ServiceSource? expectedSource)
1919
{
2020
this.ErrorCode = errorCode;
2121
this.ExpectedSource = expectedSource;

src/Microsoft.ServiceHub.Framework/ServiceMoniker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.ComponentModel;
55
using System.Diagnostics;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Globalization;
87
using System.Runtime.Serialization;
98
using JsonNET = Newtonsoft.Json;
@@ -38,6 +37,7 @@ public ServiceMoniker(string name)
3837
/// <param name="version">The version of the service or expected by the client. May be null.</param>
3938
[JsonNET.JsonConstructor]
4039
[STJ.JsonConstructor]
40+
[PolyType.ConstructorShape]
4141
public ServiceMoniker(string name, Version? version)
4242
: this(name)
4343
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.ServiceHub.Framework;
5+
using Microsoft.VisualStudio.Utilities.ServiceBroker;
6+
7+
public class MissingServiceDiagnosticsTests : RpcTestBase<IMissingServiceDiagnosticsService, MockMissingServiceDiagnosticsService>
8+
{
9+
public MissingServiceDiagnosticsTests(ITestOutputHelper logger)
10+
: base(logger, GlobalBrokeredServiceContainer.MissingServiceDiagnostics)
11+
{
12+
}
13+
14+
[Fact]
15+
public async Task RpcTest()
16+
{
17+
ServiceMoniker expectedMoniker = new("Test.MissingService", new Version(15, 0));
18+
19+
MissingServiceAnalysis result = await this.ClientProxy.AnalyzeMissingServiceAsync(expectedMoniker, TestContext.Current.CancellationToken);
20+
21+
// Verify result was serialized properly.
22+
Assert.Equal(ServiceSource.TrustedServer, result.ExpectedSource);
23+
Assert.Equal(MissingBrokeredServiceErrorCode.NotLocallyRegistered, result.ErrorCode);
24+
25+
// Verify the parameter was serialized properly.
26+
Assert.Equal(expectedMoniker, this.Service.LastReceivedMoniker);
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.ServiceHub.Framework;
5+
using Microsoft.VisualStudio.Utilities.ServiceBroker;
6+
7+
public class MockMissingServiceDiagnosticsService : IMissingServiceDiagnosticsService
8+
{
9+
internal ServiceMoniker? LastReceivedMoniker { get; set; }
10+
11+
public Task<MissingServiceAnalysis> AnalyzeMissingServiceAsync(ServiceMoniker missingServiceMoniker, CancellationToken cancellationToken)
12+
{
13+
this.LastReceivedMoniker = missingServiceMoniker;
14+
return Task.FromResult(new MissingServiceAnalysis(MissingBrokeredServiceErrorCode.NotLocallyRegistered, ServiceSource.TrustedServer));
15+
}
16+
}

0 commit comments

Comments
 (0)