Skip to content

Read assembly file version without Assembly.Location in single-file apps - #1445

Open
Ming (MaxonT) wants to merge 1 commit into
Azure:mainfrom
MaxonT:contrib/1174-auto
Open

Ming (MaxonT) wants to merge 1 commit into
Azure:mainfrom
MaxonT:contrib/1174-auto

Conversation

@MaxonT

Copy link
Copy Markdown

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.Location is an empty string, so FileVersionInfo.GetVersionInfo(...) throws and the static initializer of DurableTask.AzureStorage.Utils fails with the TypeInitializationException shown in #1174. DurableTask.Core.Common.Utils.PackageVersion reads the version the same way, so I changed both.

Each project gets a small GetAssemblyFileVersion(Assembly) helper. When Location is set it still returns FileVersionInfo.GetVersionInfo(location).FileVersion, so the normal path is unchanged. When Location is empty it reads AssemblyFileVersionAttribute instead, 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):

  • Added AssemblyFileVersionTests to DurableTask.Core.Tests and DurableTask.AzureStorage.Tests: one test for the normal path, and one that uses a dynamic assembly (empty Location, with a 1.2.3.4 file version attribute) for the fallback. dotnet test --filter FullyQualifiedName~AssemblyFileVersionTests passes 2 of 2 in each project.
  • With the empty-location check replaced by location != null, the fallback test fails with the ArgumentException: 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

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 09:18
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

some error or incompatibility when publish singlefile

2 participants