Skip to content

Commit

Permalink
Use trim-safe interop methods
Browse files Browse the repository at this point in the history
- Use trim-safe interop overloads.
- Enable AoT analyzer.
- Bump Microsoft.Data.SqlClient to 5.1.5 for net8.0.
- Bump version to 3.4.0.
  • Loading branch information
martincostello committed Feb 2, 2024
1 parent 839a3bc commit 2b66059
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,12 @@ Added overloads to support specifying the name of the Initial Catalog using the
### Added

* Add `net8.0` Target Framework Moniker.

## SqlLocalDb v3.4.0

### Changes

* Update Microsoft.Data.SqlClient dependency versions to `2.1.7` for
`netstandard2.0`/`net6.0` and `5.1.5` for `net8.0` to include fixes for
[CVE-2024-0056](https://github.com/advisories/GHSA-98g6-xh36-x2p7).
* Use interop methods that are compatible with .NET native AoT.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<VersionPrefix>3.3.1</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>
Expand Down
2 changes: 1 addition & 1 deletion src/SqlLocalDb/Interop/LocalDbInstanceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal struct LocalDbInstanceInfo : ISqlLocalDbInstanceInfo
/// <summary>
/// The size of an unmanaged type in bytes. This field is read-only.
/// </summary>
internal static readonly int MarshalSize = Marshal.SizeOf(typeof(LocalDbInstanceInfo));
internal static readonly int MarshalSize = Marshal.SizeOf<LocalDbInstanceInfo>();

/// <summary>
/// Contains the size of the <see cref="LocalDbInstanceInfo"/> struct.
Expand Down
2 changes: 1 addition & 1 deletion src/SqlLocalDb/Interop/LocalDbVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal struct LocalDbVersionInfo : ISqlLocalDbVersionInfo
/// <summary>
/// The size of an unmanaged type in bytes. This field is read-only.
/// </summary>
internal static readonly int MarshalSize = Marshal.SizeOf(typeof(LocalDbVersionInfo));
internal static readonly int MarshalSize = Marshal.SizeOf<LocalDbVersionInfo>();

/// <summary>
/// The size of the <see cref="LocalDbVersionInfo"/> structure.
Expand Down
8 changes: 7 additions & 1 deletion src/SqlLocalDb/MartinCostello.SqlLocalDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<Title>SQL LocalDB Wrapper</Title>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<!-- Mark as AoT compatible when Microsoft.Data.SqlClient and its dependencies are -->
<!--
<IsAotCompatible>true</IsAotCompatible>
-->
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<!--
Expand All @@ -40,7 +46,7 @@
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" VersionOverride="6.0.0" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<PackageReference Update="Microsoft.Data.SqlClient" VersionOverride="5.1.3" />
<PackageReference Update="Microsoft.Data.SqlClient" VersionOverride="5.1.5" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection.Abstractions" VersionOverride="8.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" VersionOverride="8.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/SqlLocalDb/SqlLocalDbApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public ISqlLocalDbInstanceInfo GetInstanceInfo(string instanceName)
EventIds.GettingInstanceInfoFailed,
instanceName);

info = (LocalDbInstanceInfo)Marshal.PtrToStructure(ptrInfo, typeof(LocalDbInstanceInfo))!;
info = Marshal.PtrToStructure<LocalDbInstanceInfo>(ptrInfo);
}
finally
{
Expand Down Expand Up @@ -670,7 +670,7 @@ public ISqlLocalDbVersionInfo GetVersionInfo(string version)
() => _api.GetVersionInfo(version, ptrInfo, size),
EventIds.GettingVersionInfoFailed);

info = (LocalDbVersionInfo)Marshal.PtrToStructure(ptrInfo, typeof(LocalDbVersionInfo))!;
info = Marshal.PtrToStructure<LocalDbVersionInfo>(ptrInfo);
}
finally
{
Expand Down

0 comments on commit 2b66059

Please sign in to comment.