Closed xclud closed 2 years ago
@xclud can you update and try again? I fixed this bug normally.
Nop. This is not working.
I installed the version 6.0.9
. My Main()
has only one line:
void Main()
{
NBitcoin.Network network = NBitcoin.Network.Main;
}
and I get this exception:
---> System.ArgumentNullException: Value cannot be null. (Param>
at System.IO.Path.Combine(String path1, String path2, String >
at NBitcoin.Bitcoin.CreateSignet()
at NBitcoin.Bitcoin.InitSignet()
at NBitcoin.Network..cctor()
--- End of inner exception stack trace ---
at NBitcoin.Network.get_Main()
I have this project as a daemon (background service) in Ubuntu. My guess is this project is trying to get the user's Home
directory and do System.IO.Path.Combine
. Home directory does not mean anything in a background service as we are not logging in with a user account. So the value null
is passed to the System.IO.Path.Combine
.
BTW, what I dislike about NBitcoin is it relates to the filesystem and network and even thought I only want to generate an offline wallet, it still initializes some directories and network connections without developer's consent.
Here is the source of the exception:
@xclud As you noticed, the exception is not specific to Ubuntu, but due to the fact your environment doesn't have either HOME
or APPDATA
environment variables which CreateSignet
relies on.
I've just submitted PR https://github.com/MetacoSA/NBitcoin/pull/1063 which uses the operating system's TEMP folder as a fallback, which is more likely to exist in scenarios like yours.
In the meantime, a simple workaround would be for you to set one of these environment variables to an existing path for your process (preferably a folder where the user running the daemon has write access to) at the start of your app, before you access any of the NBitcoin
classes. e.g.
Environment.SetEnvironmentVariable("HOME", System.IO.Path.GetTempPath(),
EnvironmentVariableTarget.Process);
Pushed 6.0.10 fixing this bug, thanks @augustoproiete to spot the source!
I run the following code from the blockchain book:
And i get the following exception:
I tried
5.x.x
and6.x.x
versions of the library and i get the same results.