Closed Sub-Zero-1 closed 5 years ago
Hi @Sub-Zero-1. Could you provide the complete stack trace so that we can see what line the NullReferenceException is occurring on?
Also, in case this is an issue of our docs being out-of-date, could you provide a link to the code snippet you were looking at on our docs?
I now know where the problem is. I suppose it has nothing to do with Braintree. This is working.
class Braintreetest
{
public Braintreetest()
{
var gateway = new BraintreeGateway
{
Environment = Braintree.Environment.PRODUCTION,
MerchantId = "mykeys",
PublicKey = "mykeys",
PrivateKey = "mykeys"
};
var searchRequest = new
TransactionSearchRequest().CreatedAt.GreaterThanOrEqualTo(DateTime.Now.AddDays(-1));
ResourceCollection<Transaction> results = gateway.Transaction.Search(searchRequest);
foreach (Transaction transaction in results)
{
Console.WriteLine("Value: " + transaction.Amount.Value);
}
}
}
//WPF
public partial class MainMaterialWindow : Window
{
Braintreetest test = new Braintreetest(); //works
..}
But if I do it in a backgroud worker it gives me an NullReferenceException for gateway.Transaction.Search(searchRequest);
private void bw_load_ui_DoWork(object sender, DoWorkEventArgs e)
{
Braintreetest test = new Braintreetest(); // does not work
}
I'm not that deep into C#, so I suppose it is my lack of knowledge here causing the fault for me. I think we can close the issue, but any explanation is much appreciated.
I don't know specifically why the same code is working in a normal scenario, but throwing an exception in the background task. I've passed your question on to some colleagues, if they have any insight, i'll post it here.
Going to close the issue, since there's nothing actionable for us to do on the sdk.
Any news on that topic? I mean, you could easily test it yourself. Just paste in some keys and run a test with and without background worker...
General information
Issue description
I was searching for transactions within the last 24h. I then populated the results in my Management System. Now, I get somehow a NullReferenceException. I am working on my Managment System, but there are no changes for the Transaction search.
Following works for me:
Following stopped to work for me(Code from your docs!):