stripe-dotnet: getFrameworkFromRegistry() throwing null reference exception on Mac
I’m trying to use the Stripe.net package in our server-side API. I started with a simple customerService.create(...) call, but got an exception with the following stack trace:
Object reference not set to an instance of an object at Stripe.Infrastructure.Client.getFrameworkFromRegistry () [0x0001a] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.Infrastructure.Client.getSystemInformation () [0x00033] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.Infrastructure.Client.GetClientUserAgentString () [0x00077] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.Infrastructure.Client.ApplyClientData () [0x0000b] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.Infrastructure.Requestor.GetRequestMessage (System.String url, System.Net.Http.HttpMethod method, Stripe.StripeRequestOptions requestOptions, System.Boolean useBearer) [0x000af] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.Infrastructure.Requestor.PostString (System.String url, Stripe.StripeRequestOptions requestOptions) [0x00006] in <d01b79e1f9c84725be1db806a232e677>:0 \n at Stripe.StripeCustomerService.Create (Stripe.StripeCustomerCreateOptions createOptions, Stripe.StripeRequestOptions requestOptions) [0x00014] in <d01b79e1f9c84725be1db806a232e677>:0 \n at [ my code ]
I’m running Visual Studio for Mac using the .NET Framework 4.5.2 (Visual Studio for Mac is what has replaced Xamarin Studio). This uses the Mono 5.0.1.1 runtime.
The actual code that triggers this issue is super basic. Here’s a gist of the relevant bits, https://gist.github.com/mickbyrne/df3835f34f5100a45e58d68002981213
This is a blocker for us at the moment. Do we need to roll our own HTTP handler for this (similar to issue https://github.com/stripe/stripe-dotnet/issues/567 re TLS?)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (8 by maintainers)
Why should a workaround be needed? Why assume Windows and ask for registry values for .NET these days?
I have studied the mono sources, and found a workround for this problem. Create the following folders (and make them accessable from whatever user is running your C# program)
/etc/mono/registry/LocalMachine/software/microsoft/net framework setup/ndp/v4/fullIn the
fullfolder at the bottom of this tree, create a filevalues.xmlcontaining the following:That is the mono equivalent of the registry key Stripe.net is looking for.
I have done this, and can go further, although I find errors later which I still have to investigate (e.g. transactions taking ages, and certificate exceptions).
Hey everyone, thanks for the feedback! We are planning on removing the registry access entirely – as it turns out, even on Windows platforms there is no guarantee that the values read from the registry match that of the .NET runtime actually in use.
I don’t have a firm ETA to provide but we’re aiming to fix this ASAP. Thanks for your patience everyone!
This applies to Linux as well. You can’t use registry keys on Mono - there is no registry! My project, due for launch next week, is held up by this. I notice from the source that this code is inside
#if NET45. Is there a NuGet package withNET45NOT defined?@fred-stripe - It’s worth noting that this block of code is also one of the two sources of problems in the permissions issue #971. It requires full permissions to inspect the registry like it does, so it might be prudent to just fully replace it in favor of something a bit more naive. It’s sad, because we assumed this wouldn’t make any impact when we added it last month, but it clearly did in a few unexpected ways.
@mickbyrne - Thanks so much for filing this!