From bebb2f4a82de782d522913fbe947c72b6593a51a Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Tue, 10 Oct 2023 10:29:33 +0200 Subject: [PATCH] Fallback to `AssemblyVersion` if `InformalVersion` is `NullOrEmpty` (#2705) --- src/Sentry/Reflection/AssemblyExtensions.cs | 6 +----- .../Internals/ApplicationVersionLocatorTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Sentry/Reflection/AssemblyExtensions.cs b/src/Sentry/Reflection/AssemblyExtensions.cs index a4f0a855fe..104dca2005 100644 --- a/src/Sentry/Reflection/AssemblyExtensions.cs +++ b/src/Sentry/Reflection/AssemblyExtensions.cs @@ -30,7 +30,7 @@ public static SdkVersion GetNameAndVersion(this Assembly asm) try { var informationalVersion = assembly.GetCustomAttribute()?.InformationalVersion; - if (informationalVersion != null) + if (!string.IsNullOrEmpty(informationalVersion)) { return informationalVersion; } @@ -41,10 +41,6 @@ public static SdkVersion GetNameAndVersion(this Assembly asm) // therefore this method uses a try/catch to make sure this method always returns a value } - // Note: even though the informational version could be "invalid" (e.g. string.Empty), it should - // be used for versioning and the software should not fallback to the assembly version string. - // See https://github.com/getsentry/sentry-dotnet/pull/1079#issuecomment-866992216 - // TODO: Lets change this in a new major to return the Version as fallback return assembly.GetName().Version?.ToString(); } } diff --git a/test/Sentry.Tests/Internals/ApplicationVersionLocatorTests.cs b/test/Sentry.Tests/Internals/ApplicationVersionLocatorTests.cs index ccd4be9e37..7dacfc8c54 100644 --- a/test/Sentry.Tests/Internals/ApplicationVersionLocatorTests.cs +++ b/test/Sentry.Tests/Internals/ApplicationVersionLocatorTests.cs @@ -36,11 +36,11 @@ public void GetCurrent_VersionWithPrefix_ReturnsVersionAsIs() [Theory] [InlineData("")] - public void GetCurrent_InvalidCases_ReturnsNull(string version) + public void GetCurrent_InvalidCases_DoesNotReturnNull(string version) { var asm = AssemblyCreationHelper.CreateWithInformationalVersion(version); var actual = ApplicationVersionLocator.GetCurrent(asm); - Assert.Null(actual); + Assert.NotNull(actual); } [Fact]