rabbitmq / rabbitmq-stream-dotnet-client

RabbitMQ client for the stream protocol
https://rabbitmq.github.io/rabbitmq-stream-dotnet-client/stable/htmlsingle/index.html
Other
122 stars 41 forks source link

Publishing as single file leads to TypeInitializationException #365

Closed doerig closed 8 months ago

doerig commented 8 months ago

Describe the bug

When RabbitMQ Stream client is used in a project that is published as a single file, an Exception is thrown:

System.TypeInitializationException: The type initializer for 'RabbitMQ.Stream.Client.Version' threw an exception.
 ---> System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at RabbitMQ.Stream.Client.Version..cctor() in /_/RabbitMQ.Stream.Client/Version.cs:line 15

When published as a single file, the assemblies are bundled together and do not exist as individual files. Assembly.Location returns an empty string in this case, and this causes FileVersionInfo.GetVersionInfo to fail.

In my project, I use Assembly.GetName().Version.ToString() to log the assembly Version, maybe this could also be used in this case.

Reproduction steps

  1. Publish a project that uses RabbitMQ Stream Client as single file: dotnet publish --self-contained true -p:PublishSingleFile=true test.csproj
  2. Start the published executable

Expected behavior

RabbitMQ Stream Client should support single file publish

Additional context

https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/warnings/overview

lukebakken commented 8 months ago

Thanks, please feel free to submit a PR to fix this issue. We would appreciate it.