Comments (7)
Thanks. Regenerated.
from azure-notificationhubs-dotnet.
Howdy @alaskanrogue,
Try switching the line
if (outcome.NotificationId != "")
to
if (!string.IsNullOrWhitespace(outcome.NotificationId))
Unless you're using the "Standard" SKU (e.g. most expensive SKU) of Notification Hubs, we don't return a Notifcation ID. I believe that value just happens to be null instead of the empty string, and the check above is missing it and trying to call a function that requires a notification ID.
@zhangeugenia and I were just playing around with this, and while the change above may fix this issue from above:
:"System.ArgumentNullException","message":"Value cannot be null.\r\nParameter name: notificationId"
It doesn't explain why that value is null for you in the first place. In our code, we're seeing an empty string returned, never null.
However, when we execute your code path, we can confirm that when we pass true
for enableTestSend
in NotificationHubClient.CreateClientFromConnectionString
we get the same error you're seeing in this comment. I'll double check whether this is supposed to be supported or not.
from azure-notificationhubs-dotnet.
Howdy @alaskanrogue,
The stack trace included above doesn't give me quite enough to get started on debugging this issue. Mind providing a representative snippet of code that results in the error you're seeing?
from azure-notificationhubs-dotnet.
Howdy back, @marstr,
Below is the class implementation. It is designed to handle notifications to basically all device types. If the parameter is not enabled, UWP and iOS is delivering raw messages; Android is not, hence my enabling the parameter. I am consistently being told "Target not found". StartNotificationTask() contains the hub call.
class AsynchNotification
{
protected int deviceType;
protected string ownerUri;
protected WindowsNotification winMessage;
protected string notice;
protected bool receivedResponse;
public string finalSessionStatus;
protected bool responseReceived;
protected bool notificationAborted;
protected DateTime startTime;
protected int responseTimeSpan = 3;
protected NotificationRequestHandler handler;
public AsynchNotification(NotificationRequestHandler callHandler)
{
handler = callHandler;
}
public void StartNotificationWork(int type, string uri, WindowsNotification notificationToSend, string noticeToSend)
{
deviceType = type;
ownerUri = uri;
winMessage = notificationToSend;
notice = noticeToSend;
ThreadPool.QueueUserWorkItem(new WaitCallback(StartNotificationTask), null);
}
private async void StartNotificationTask(Object workItemState)
{
bool debug = false;
bool enableTestSend = false;
NotificationOutcome outcome;
NotificationDetails details;
// Set the Notification Hubs credentials for the Mobile App
try
{
// Remark if not debugging
debug = true;
enableTestSend = true;
// Create hub instance
string notificationHubConnection = "Endpoint=sb://identitycheckpointnotifications.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=53Be0m1oGSuDnbyr3aGSO+nraHGPy/id/khhvnHzdWc=";
string notificationHubName = "IdentityCheckpointNotificationsHub";
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName, enableTestSend);
// Send the push notification.
try
{
outcome = await hub.SendDirectNotificationAsync(winMessage, ownerUri);
if (outcome.NotificationId != "")
{
details = await hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId);
while (details.State.Equals(2))
{
details = await hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId);
await Task.Delay(1000);
}
if (details.State.Equals(0) || details.State.Equals(3))
{
handler.notificationSent = true;
if (details.State.Equals(0))
{
handler.notificationEnqueued = true;
}
}
else
{
handler.notificationSent = false;
if (debug)
{
string uri = details.PnsErrorDetailsUri;
}
}
handler.notificationProcessed = true;
}
else
{
if (outcome.State.Equals(0) || outcome.State.Equals(3))
{
handler.notificationSent = true;
if (outcome.State.Equals(0))
{
handler.notificationEnqueued = true;
}
}
else
{
handler.notificationSent = false;
if (debug)
{
List <Microsoft.Azure.NotificationHubs.RegistrationResult> results = outcome.Results;
}
}
handler.notificationProcessed = true;
}
}
catch (System.Exception ex)
{
finalSessionStatus = "An error occurred during query execution: " + ex;
responseReceived = false;
notificationAborted = true;
throw new ApplicationException("An error occurred during query execution: ", ex);
}
startTime = DateTime.Now;
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.Timeout)
{
receivedResponse = false;
finalSessionStatus = "No request was able to be sent within the allocated time period.";
responseReceived = false;
}
else
{
finalSessionStatus = "An error occurred during query execution: " + ex;
responseReceived = false;
notificationAborted = true;
throw new ApplicationException("An error occurred during query execution: ", ex);
}
}
}
}
from azure-notificationhubs-dotnet.
Debugging just now a different issue, but enableTestSend enabled because of having created the code snippet, I caught this exception.
from azure-notificationhubs-dotnet.
@alaskanrogue, looks like you accidentally included a SharedAccessKey
in the post above. Please take a moment to generate a new primary access policy for your Notification Hub, as this one has been compromised.
This gives me what I need to start investigating though, thank you!
from azure-notificationhubs-dotnet.
I'm going to close this issue out, under the assumption that this operation truly is not supported while using enableTestSend
. However, if there's any reason to believe otherwise, I'm happy to open this issue back up.
from azure-notificationhubs-dotnet.
Related Issues (20)
- [BUG] HTTP403 responses are interpreted as "Throttled"
- [BUG] enableTestSend gives error "Root element is missing"
- [BUG] GCM HTTP protocol parameters not passed on ?
- [BUG] GetRegistrationsByChannel filters to ChannelUri
- [BUG] Release 4.1.1 is not published to NuGet so issues #199 & #205 are not fixed HOT 4
- ASP.NET MVC 5 .NET 4.7.2 hangs when calling InstallationExists or DeleteInstallation HOT 2
- Bulk import is still on Running state only
- Best practice using with azure functions (socket exceptions)
- [BUG] NotificationHubClient.UpdateRegistrationAsync throws MessagingException
- [BUG] Send Template Notification Fails (WNS)
- [BUG] - Expiration Time for installation/registration is being set to to default value when use PatchInstallation
- Issue while sending Notification based on different templates (Silent & Standard)
- [QUERY] what is the release cadence?
- [FEATURE REQ] Update Firebase Messaging to stop using old FCM APIs HOT 1
- Firebase Legacy HTTP Send API are to be decommissioned after June 20, 2024 HOT 2
- [BUG] NotificationHubClient.GetRegistrationsByChannelAsync not returning any result on IOS
- [BUG] Azure notification hub doesn't accept token format from firebase_messaging
- [BUG] Notifications continue to send after deleting an installation HOT 2
- [Question] Azure Notification Hub on MAUI HOT 25
- [BUG] MessagingEntityNotFoundException when getting notification outcome details
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-notificationhubs-dotnet.