I'm getting a NullReferenceException and I really have no idea on why it is happening. The Exception is thrown inside my EventHandler for the DataRequested method of the DataTransferManager. Here's the method:
void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
// The Title is mandatory
request.Data.Properties.Title = TranslationManager.GetLocalizedString("SomeTitle");
// SharedString is never null, I get it with a ?? String.Empty
request.Data.SetText(SharedString);
}
And this is StackTrace:
at Windows.ApplicationModel.DataTransfer.DataPackage.SetText(String value)
at OneLocker.Views.CardPage.dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
To add the EventHandler, I just do the usual:
DataTransferManager DataTransferManager = DataTransferManager.GetForCurrentView();
DataTransferManager.DataRequested += dataTransferManager_DataRequested;
What's bugging me is that the EventHandler works fine most of the times it is called, it's just crashing for some users of my app. Also, I really don't get what is causing the Exception. The request variable is taken from the event args, so how is it possible to be null? I saw the code examples on the MSDN site, and they never did some kind of error checking there, they just assumed that it would never be null. So how is it that it is crashing here?
Thank you so much for your help!
Sergio