Skip to content

Commit

Permalink
Fallback to AssemblyVersion if InformalVersion is NullOrEmpty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored and vaind committed Oct 14, 2023
1 parent 7e0e916 commit bebb2f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/Sentry/Reflection/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static SdkVersion GetNameAndVersion(this Assembly asm)
try
{
var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (informationalVersion != null)
if (!string.IsNullOrEmpty(informationalVersion))
{
return informationalVersion;
}
Expand All @@ -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();
}
}
4 changes: 2 additions & 2 deletions test/Sentry.Tests/Internals/ApplicationVersionLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit bebb2f4

Please sign in to comment.