Repository navigation
Read assembly file version without Assembly.Location in single-file apps - #1445
Open
Ming (MaxonT) wants to merge 1 commit into
Open
Ming (MaxonT) wants to merge 1 commit into
Ming (MaxonT) wants to merge 1 commit into
Conversation
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the version-lookup fallback that handles empty assembly locations in single-file applications.
No open issues 🎉
What changed in this PR
Addresses #1174 by making Core and Azure Storage version lookup tolerate an empty Assembly.Location, preventing the reported static-initializer failure in single-file applications.
Changes:
- Preserve file-based version lookup when an assembly location is available.
- Fall back to
AssemblyFileVersionAttribute, or an empty string when the attribute is absent. - Add tests for normal lookup and the empty-location fallback; fallback tests are excluded on .NET Framework.
| File | Description |
|---|---|
| Test/DurableTask.Core.Tests/AssemblyFileVersionTests.cs | Tests Core version lookup and attribute fallback. |
| Test/DurableTask.AzureStorage.Tests/AssemblyFileVersionTests.cs | Tests Azure Storage version lookup and attribute fallback. |
| src/DurableTask.Core/Common/Utils.cs | Uses the fallback helper to initialize PackageVersion. |
| src/DurableTask.AzureStorage/Utils.cs | Uses the fallback helper to initialize ExtensionVersion. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is aimed at the error when publishing durabletask as a single file; the title was all I had, so I can't say it matches your exact failure. Which publish settings do you use?
In a single-file publish
Assembly.Locationis an empty string, soFileVersionInfo.GetVersionInfo(...)throws and the static initializer ofDurableTask.AzureStorage.Utilsfails with theTypeInitializationExceptionshown in #1174.DurableTask.Core.Common.Utils.PackageVersionreads the version the same way, so I changed both.Each project gets a small
GetAssemblyFileVersion(Assembly)helper. WhenLocationis set it still returnsFileVersionInfo.GetVersionInfo(location).FileVersion, so the normal path is unchanged. WhenLocationis empty it readsAssemblyFileVersionAttributeinstead, and returns an empty string if that is missing too.What I ran, on my machine (macOS, .NET SDK 10.0.404, net8.0 target):
AssemblyFileVersionTeststoDurableTask.Core.TestsandDurableTask.AzureStorage.Tests: one test for the normal path, and one that uses a dynamic assembly (emptyLocation, with a1.2.3.4file version attribute) for the fallback.dotnet test --filter FullyQualifiedName~AssemblyFileVersionTestspasses 2 of 2 in each project.location != null, the fallback test fails with theArgumentException: The value cannot be an empty string (Parameter 'path')from the issue, so the test does cover the change.Not verified: I did not publish an actual single-file app and run it, I did not run the full test suites (many need Azurite or Service Bus), and the net48 target was not built. The fallback test is compiled out for net48 because dynamic assemblies behave differently there.
Resolves #1174