Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/StreamJsonRpc/Reflection/ProxyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,22 +381,17 @@ private static bool ProxyImplementsCompatibleSetOfInterfaces(
JsonRpcProxyOptions? options)
{
HashSet<Type> proxyInterfaces = [.. proxyClass.GetInterfaces()];
if (!proxyInterfaces.Remove(contractInterface))
{
return false;
}

foreach (Type addl in additionalContractInterfaces)
// Put all the interfaces required into a set so that duplicates are removed.
HashSet<Type> requiredInterfaces = [contractInterface, .. additionalContractInterfaces];
foreach ((Type addl, _) in implementedOptionalInterfaces)
{
if (!proxyInterfaces.Remove(addl))
{
return false;
}
requiredInterfaces.Add(addl);
}

foreach ((Type addl, _) in implementedOptionalInterfaces)
foreach (Type reqd in requiredInterfaces)
{
if (!proxyInterfaces.Remove(addl))
if (!proxyInterfaces.Remove(reqd))
{
return false;
}
Expand All @@ -421,22 +416,35 @@ private static bool ProxyImplementsCompatibleSetOfInterfaces(
continue;
}

bool ok = false;
foreach (Type addl in additionalContractInterfaces)
{
if (remaining.IsAssignableFrom(addl))
{
ok = true;
continue;
}
}

if (ok)
{
continue;
}

foreach ((Type addl, _) in implementedOptionalInterfaces)
{
if (remaining.IsAssignableFrom(addl))
{
ok = true;
continue;
}
}

if (ok)
{
continue;
}
Comment thread
AArnott marked this conversation as resolved.

// This is an extra, unwanted interface.
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/StreamJsonRpc/Reflection/ProxyInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal ProxyInputs(ProxyInputs copyFrom)
/// <summary>
/// Gets a description of the requirements on the proxy to be used.
/// </summary>
internal string Requirements => $"Implementing interface(s): {string.Join(", ", [this.ContractInterface, .. this.AdditionalContractInterfaces.Span])}.";
internal string Requirements => $"Implementing interface(s): {string.Join(", ", [this.ContractInterface, .. this.AdditionalContractInterfaces.Span])}";

/// <summary>
/// Sorts <paramref name="list"/> so that:
Expand Down
7 changes: 4 additions & 3 deletions test/StreamJsonRpc.Tests/JsonRpcProxyGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,11 @@ private static void DynamicAssembliesKeyedByAssemblyLoadContext_Helper(JsonRpcPr

#if NO_INTERCEPTORS
public class Dynamic(ITestOutputHelper logger) : JsonRpcProxyGenerationTests(logger, JsonRpcProxyOptions.ProxyImplementation.AlwaysDynamic);
#else
#endif

public class SourceGenerated(ITestOutputHelper logger) : JsonRpcProxyGenerationTests(logger, JsonRpcProxyOptions.ProxyImplementation.AlwaysSourceGenerated)
{
#if !NO_INTERCEPTORS
/// <summary>
/// The interceptor cannot fallback to dynamic proxies at runtime when the Options demands it,
/// because doing so would generate linker warnings for NativeAOT apps.
Expand Down Expand Up @@ -1066,9 +1068,8 @@ public async Task CheckedInProxiesFromPastGenerationsStillWork()

Assert.Equal(0, failures);
}
}

#endif
}

public class EmptyClass
{
Expand Down