Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

.NET 5 Single file deployment throws exception #33

Open
raphibolliger opened this issue Jan 16, 2021 · 1 comment
Open

.NET 5 Single file deployment throws exception #33

raphibolliger opened this issue Jan 16, 2021 · 1 comment

Comments

@raphibolliger
Copy link

Since .NET 5 the Assembly.Location API returns an empty string when the app is deployed as single file executable.
https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file

This prevents the library from using with a single file deployment.

Error
The basePath variable will be empty.

var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

Path.Combine later on will throw an exception.
var targetPath = Path.Combine(basePath, filename);

Exception

System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at Unosquare.WiringPi.Resources.EmbeddedResources.ExtractAll()
   at Unosquare.WiringPi.BootstrapWiringPi.Bootstrap()
   at Unosquare.RaspberryIO.Pi.Init[T]()
   at HorseFeeder.Raspberry.InitializeService.InitializeRaspberryPi()

Possible solution
I'm not 100% sure but maybe it's possible to use AppContext.BaseDirectory to get the basePath.
https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.basedirectory?view=net-5.0#System_AppContext_BaseDirectory

@geoperez
Copy link
Member

We are looking for maintainers, you can apply at https://adoptoposs.org/p/67b02bee-a00e-446a-a321-c1a6449014bc

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants