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
2 changes: 1 addition & 1 deletion src/AnalyzerUser.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<EnableStreamJsonRpcInterceptors>true</EnableStreamJsonRpcInterceptors>
<EnableStreamJsonRpcInterceptors Condition="'$(EnableStreamJsonRpcInterceptors)'==''">true</EnableStreamJsonRpcInterceptors>
</PropertyGroup>
<ItemGroup>
<AnalyzerProjectReference Include="$(RepoRootPath)src\StreamJsonRpc.Analyzers\StreamJsonRpc.Analyzers.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/StreamJsonRpc/StreamJsonRpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
<!-- Enable warnings regarding AOT compatibility. Learn more about testing strategies at https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/ -->
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
<EnableStreamJsonRpcInterceptors>false</EnableStreamJsonRpcInterceptors>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx" />
Expand Down
16 changes: 16 additions & 0 deletions test/StreamJsonRpc.Analyzer.Tests/ProxyGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ void Foo(System.IO.Stream s)
""");
}

/// <summary>
/// Tracks the scenario of unknown types being passed to the <c>Attach</c> method.
/// </summary>
/// <remarks>
/// Although the type is unknown, we still want to redirect the API call to
/// NativeAOT safe alternatives (that will fail at runtime if the proxy hasn't been generated).
/// Projects are required to opt-in to this behavior, so we consider it safe.
/// </remarks>
[Fact]
public async Task Interceptor_UnknownTypes_Generic()
{
Expand All @@ -602,6 +610,14 @@ void Foo<T>(System.IO.Stream s) where T: class
""");
}

/// <summary>
/// Tracks the scenario of unknown types being passed to the <c>Attach</c> method.
/// </summary>
/// <remarks>
/// Although the type is unknown, we still want to redirect the API call to
/// NativeAOT safe alternatives (that will fail at runtime if the proxy hasn't been generated).
/// Projects are required to opt-in to this behavior, so we consider it safe.
/// </remarks>
[Fact]
public async Task Interceptor_UnknownTypes_NonGeneric()
{
Expand Down
19 changes: 19 additions & 0 deletions test/StreamJsonRpc.Tests/ArchitectureTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

public class ArchitectureTests
{
/// <summary>
/// Verifies that no interceptors are present in the StreamJsonRpc assembly.
/// </summary>
/// <remarks>
/// Our own library intentionally has NativeAOT safe and unsafe APIs, and the unsafe ones should
/// <em>not</em> be rewritten to call the safe APIs, since that can cause runtime exceptions when
/// our callers are not prepared for NativeAOT safety's restrictions.
/// </remarks>
[Fact]
public void NoInterceptors()
{
Assert.DoesNotContain(typeof(JsonRpc).Assembly.GetTypes(), t => t.Namespace == "StreamJsonRpc.Generated");
Comment thread
AArnott marked this conversation as resolved.
Comment thread
AArnott marked this conversation as resolved.
}
}