Skip to content

Commit 4727ab3

Browse files
authored
Merge pull request #18 from NativeScript/fix/dotnet-bridge-warnings
fix: silence dotnet-bridge build warnings
2 parents d8f9e23 + c2f5024 commit 4727ab3

8 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎dotnet-bridge/Bridge.Dispatch.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private static DispatchResult Box(object? value)
351351
: DispatchResult.Handle(id, typeName);
352352
}
353353

354-
private static bool IsAwaitable(object value, Type t)
354+
private static bool IsAwaitable(object? value, Type t)
355355
{
356356
if (value is Task || value is ValueTask) return true;
357357
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ValueTask<>)) return true;

‎dotnet-bridge/Bridge.Proxy.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ private static DispatchResult CreateJsSubclass(
421421
// look up or dynamically emit a proxy for the correct base class.
422422
string? resolveFrom = typeName;
423423
if (!string.IsNullOrEmpty(assemblyName)
424-
&& typeName != null
425424
&& typeName.StartsWith("com.tns.gen.winrt.", StringComparison.Ordinal))
426425
{
427426
resolveFrom = assemblyName;

‎dotnet-bridge/Bridge.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static string GetNamespaceAssemblyMapJson()
115115
var simple = Path.GetFileNameWithoutExtension(file);
116116
if (string.IsNullOrEmpty(simple)) continue;
117117

118-
Assembly asm = AppDomain.CurrentDomain.GetAssemblies()
118+
Assembly? asm = AppDomain.CurrentDomain.GetAssemblies()
119119
.FirstOrDefault(a => string.Equals(a.GetName().Name, simple, StringComparison.OrdinalIgnoreCase));
120120
if (asm is null)
121121
{
@@ -540,7 +540,7 @@ public static int RegisterUnhandledExceptionCallback(int callbackId)
540540
{
541541
var handlerType = ev.EventHandlerType;
542542
var method = typeof(Bridge).GetMethod(nameof(CoreApplicationUnhandledErrorHandler), BindingFlags.NonPublic | BindingFlags.Static);
543-
if (method != null)
543+
if (handlerType != null && method != null)
544544
{
545545
var del = Delegate.CreateDelegate(handlerType, method);
546546
ev.AddEventHandler(null, del);
@@ -633,7 +633,7 @@ private static IntPtr ObtainNativePtr(object obj)
633633
try
634634
{
635635
var iidLocal = s_iidIInspectable;
636-
var hr = Marshal.QueryInterface(iunknown, ref iidLocal, out var inspectable);
636+
var hr = Marshal.QueryInterface(iunknown, in iidLocal, out var inspectable);
637637
if (hr == 0 && inspectable != IntPtr.Zero)
638638
{
639639
Marshal.Release(iunknown);

‎dotnet-bridge/DotNetBridge.csproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
host process is already running on net10. LatestMajor accepts any version >= 9. -->
1717
<RollForward>LatestMajor</RollForward>
1818
</PropertyGroup>
19+
<ItemGroup>
20+
<!-- The bridge only runs inside a Windows host, but the TFM stays plain net9.0 so the
21+
net9.0 test/benchmark projects can reference it. Declaring the platform here keeps
22+
CA1416 quiet for the Marshal COM APIs. Skipped when an OS-specific TFM already emits it. -->
23+
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatformAttribute" Condition="'$(TargetPlatformIdentifier)' == ''">
24+
<_Parameter1>windows</_Parameter1>
25+
</AssemblyAttribute>
26+
</ItemGroup>
1927
<Target Name="WriteDotNetToolDone" AfterTargets="Publish">
2028
<PropertyGroup>
2129
<DotNetToolDoneFile>$(MSBuildProjectDirectory)\publish\.dotnet_tool_done</DotNetToolDoneFile>

‎template/framework/dotnet-bridge/Bridge.Dispatch.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private static DispatchResult Box(object? value)
351351
: DispatchResult.Handle(id, typeName);
352352
}
353353

354-
private static bool IsAwaitable(object value, Type t)
354+
private static bool IsAwaitable(object? value, Type t)
355355
{
356356
if (value is Task || value is ValueTask) return true;
357357
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ValueTask<>)) return true;

‎template/framework/dotnet-bridge/Bridge.Proxy.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ private static DispatchResult CreateJsSubclass(
421421
// look up or dynamically emit a proxy for the correct base class.
422422
string? resolveFrom = typeName;
423423
if (!string.IsNullOrEmpty(assemblyName)
424-
&& typeName != null
425424
&& typeName.StartsWith("com.tns.gen.winrt.", StringComparison.Ordinal))
426425
{
427426
resolveFrom = assemblyName;

‎template/framework/dotnet-bridge/Bridge.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static string GetNamespaceAssemblyMapJson()
115115
var simple = Path.GetFileNameWithoutExtension(file);
116116
if (string.IsNullOrEmpty(simple)) continue;
117117

118-
Assembly asm = AppDomain.CurrentDomain.GetAssemblies()
118+
Assembly? asm = AppDomain.CurrentDomain.GetAssemblies()
119119
.FirstOrDefault(a => string.Equals(a.GetName().Name, simple, StringComparison.OrdinalIgnoreCase));
120120
if (asm is null)
121121
{
@@ -540,7 +540,7 @@ public static int RegisterUnhandledExceptionCallback(int callbackId)
540540
{
541541
var handlerType = ev.EventHandlerType;
542542
var method = typeof(Bridge).GetMethod(nameof(CoreApplicationUnhandledErrorHandler), BindingFlags.NonPublic | BindingFlags.Static);
543-
if (method != null)
543+
if (handlerType != null && method != null)
544544
{
545545
var del = Delegate.CreateDelegate(handlerType, method);
546546
ev.AddEventHandler(null, del);
@@ -633,7 +633,7 @@ private static IntPtr ObtainNativePtr(object obj)
633633
try
634634
{
635635
var iidLocal = s_iidIInspectable;
636-
var hr = Marshal.QueryInterface(iunknown, ref iidLocal, out var inspectable);
636+
var hr = Marshal.QueryInterface(iunknown, in iidLocal, out var inspectable);
637637
if (hr == 0 && inspectable != IntPtr.Zero)
638638
{
639639
Marshal.Release(iunknown);

‎template/framework/dotnet-bridge/DotNetBridge.csproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
host process is already running on net10. LatestMajor accepts any version >= 9. -->
1717
<RollForward>LatestMajor</RollForward>
1818
</PropertyGroup>
19+
<ItemGroup>
20+
<!-- The bridge only runs inside a Windows host, but the TFM stays plain net9.0 so the
21+
net9.0 test/benchmark projects can reference it. Declaring the platform here keeps
22+
CA1416 quiet for the Marshal COM APIs. Skipped when an OS-specific TFM already emits it. -->
23+
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatformAttribute" Condition="'$(TargetPlatformIdentifier)' == ''">
24+
<_Parameter1>windows</_Parameter1>
25+
</AssemblyAttribute>
26+
</ItemGroup>
1927
<Target Name="WriteDotNetToolDone" AfterTargets="Publish">
2028
<PropertyGroup>
2129
<DotNetToolDoneFile>$(MSBuildProjectDirectory)\publish\.dotnet_tool_done</DotNetToolDoneFile>

0 commit comments

Comments
 (0)