Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS push notification fails with NotificationHubClient in release mode #24118

Open
intellimedhu opened this issue Aug 9, 2024 · 15 comments
Open
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@intellimedhu
Copy link

Description

I was able to send push notifications in debug to my iPhone, through AzureNotificationHub.
But it fails in release mode (using TestFlight).

Using nuget package: Microsoft.Azure.NotificationHubs 4.2.0

During debugging, I found out that it fails to register to the NotificationHub.
When calling NotificationHubClient.CreateOrUpdateRegistrationAsync() method, it throws an exception.

Exception:

UnexpectedElementExpectingElements, Element, DeviceToken, http://schemas.microsoft.com/netservices/2010/10/servicebus/connect, PushVariables
System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, Int32 memberIndex, Int32 requiredIndex, XmlDictionaryString[] memberNames)

I tried enabling the Mono interpreter, just like they recommended in a previous issue and in the documentation but the problem still remains.

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <MtouchInterpreter>-all</MtouchInterpreter>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <MtouchInterpreter>all</MtouchInterpreter>
</PropertyGroup>

Steps to Reproduce

  1. Create new MAUI app
  2. Add Microsoft.Azure.NotificationHubs nuget
  3. Try to register to NotificationHub

Link to public reproduction project repository

No response

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17.5.1

Did you find any workaround?

No

Relevant log output

UnexpectedElementExpectingElements, Element, DeviceToken, http://schemas.microsoft.com/netservices/2010/10/servicebus/connect, PushVariables
System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, Int32 memberIndex, Int32 requiredIndex, XmlDictionaryString[] memberNames)
@intellimedhu intellimedhu added the t/bug Something isn't working label Aug 9, 2024
Copy link
Contributor

github-actions bot commented Aug 9, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@jfversluis
Copy link
Member

Could you maybe try this and see if that helps: #11131 (comment)

@jfversluis jfversluis added platform/iOS 🍎 area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) s/needs-info Issue needs more info from the author labels Aug 9, 2024
@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Aug 14, 2024
@intellimedhu
Copy link
Author

I also tried it with this:

<MtouchExtraArgs Condition="'$(TargetFramework)' == '$(iOSTargetFramework)' and '$(Configuration)' == 'Release'">
        --linkskip=Microsoft.Azure.NotificationHubs
</MtouchExtraArgs>

but this causes the whole app to crash, I can't even start it.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity labels Aug 14, 2024
@PureWeen
Copy link
Member

@rolfbjarne @dalexsoto thoughts?

@intellimedhu can you attach the exception you are seeing?

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Aug 16, 2024
@rolfbjarne
Copy link
Member

@rolfbjarne @dalexsoto thoughts?

No idea what's going on here, but the exception details + stack trace might help us to start looking in the right direction.

@intellimedhu
Copy link
Author

@rolfbjarne @dalexsoto thoughts?

@intellimedhu can you attach the exception you are seeing?

ErrorInLine, 1, 995
UnexpectedElementExpectingElements, Element, DeviceToken, http://schemas.microsoft.com/netservices/2010/10/servicebus/connect, PushVariables---- at

System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator, Int32, Int32, XmlDictionaryString[]) at

System.Runtime.Serialization.XmlObjectSerializerReadContext.GetMemberIndexWithRequiredMembers(XmlReaderDelegator, XmlDictionaryString[], XmlDictionaryString[], Int32, Int32, ExtensionDataObject) at

System.Runtime.Serialization.ReflectionXmlReader.ReflectionReadMembers(XmlReaderDelegator, XmlObjectSerializerReadContext,  XmlDictionaryString[],  XmlDictionaryString[], ClassDataContract, Object&) at

System.Runtime.Serialization.ReflectionReader.ReflectionReaderClass(XmlReaderDelegator, XmlObjectSerializerReadContext,
XmlDictionaryString[],  XmlDictionaryString[], ClassDataContract) at

System.Runtime.Serialization.ReflectionXmlClassReader.ReflectionReaderClass(XmlReaderDelegator xmlReader, 
XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNameSpaces) at

System.Runtime.Serialization.DataContracts.ClassDataContract.ReadXmlValue(XmlReaderDelegator, XmlObjectSerializerReadContext ) at

System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract, XmlReaderDelegator ) at

System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator , String, String,
Type, DataContract&) at

System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator , Type, DataContract,
String, String) at

System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator , Boolean, DataContractResolver ) at

System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadObjectHandleExceptions(XmlReaderDelegator, Boolean, DataContractResolver ) at

System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlReader ) at

Microsoft.Azure.NotificationHubs.Messaging.EntityDescriptionSerializer.Deserialize(XmlReader reader, String typeName) at

Microsoft.Azure.NotificationHubs.NotificationHubClient<ReadEntityAsync>d_219` 1[[Microsoft.Azure.NotificationHubs.RegistrationDescription, Microsoft.Azure.NotificationHubs, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at

Microsoft.Azure.NotificationHubs.NotificationHubClient.<>c_DisplayClass209_0`1.<<CreateOrUpdateRegistrationImplAsync>b_0>d[[Microsoft.Azure.NotificationHubs.RegistrationDescription, Microsoft.Azure.NotificationHubs, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() 
--- End of stack trace from previous location --- 

at

Microsoft.Azure.NotificationHubs.NotificationHubRetryPolicy.<RunOperation>d_4`1[[Microsoft.Azure.NotificationHubs.RegistrationDescription, Microsoft.Azure.NotificationHubs, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at

Microsoft.Azure.NotificationHubs.NotificationHubRetryPolicy.<RunOperation>d_4`1[[Microsoft.Azure.NotificationHubs.RegistrationDescription, Microsoft.Azure.NotificationHubs, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at

Microsoft.Azure.NotificationHubs.NotificationHubClient.<CreateOrUpdateRegistrationImplAsync>d_209`1
[[Microsoft.Azure.NotificationHubs.RegistrationDescription, Microsoft.Azure.NotificationHubs, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Aug 23, 2024
@rolfbjarne
Copy link
Member

I wonder if it's the linker removing stuff.

Can you try disable the linker + enable the interpreter:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchLink>None</MtouchLink>
</PropertyGroup>

and see if that changes anything?

@intellimedhu
Copy link
Author

I wonder if it's the linker removing stuff.

Can you try disable the linker + enable the interpreter:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchLink>None</MtouchLink>
</PropertyGroup>

and see if that changes anything?

Sorry for the late reply. This causes the whole app to crash, it can't even start.

@rolfbjarne
Copy link
Member

I wonder if it's the linker removing stuff.
Can you try disable the linker + enable the interpreter:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchLink>None</MtouchLink>
</PropertyGroup>

and see if that changes anything?

Sorry for the late reply. This causes the whole app to crash, it can't even start.

What about this? This should be pretty close to the working Debug configuration.

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchUseLlvm>false</MtouchUseLlvm>
</PropertyGroup>

@intellimedhu
Copy link
Author

I wonder if it's the linker removing stuff.
Can you try disable the linker + enable the interpreter:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchLink>None</MtouchLink>
</PropertyGroup>

and see if that changes anything?

Sorry for the late reply. This causes the whole app to crash, it can't even start.

What about this? This should be pretty close to the working Debug configuration.

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <UseInterpreter>true</UseInterpreter>
    <MtouchUseLlvm>false</MtouchUseLlvm>
</PropertyGroup>

This solved the problem, thank you! I was able to receive notifications, which were sent through the Azure Hub.
These changes how much affect the app (size, speed)?

@rolfbjarne
Copy link
Member

This solved the problem, thank you!

That's great!

It looks like this is a problem with our LLVM support then. Would you be able to provide a test project we could use to reproduce the problem in order to track it down and fix it?

These changes how much affect the app (size, speed)?

Not compiling with LLVM can make the app slightly smaller (LLVM typically produces more code) although also slightly slower. Depending on the app, the slowness can range from impossible to measure to a noticeable delay, in particular for apps that use a lot of math in C# (for instances games). Most UI apps won't see any difference whatsoever though. If your app feels responsive as usual, then you're fine performance-wise.

@jaosnz-rep jaosnz-rep added the s/triaged Issue has been reviewed label Sep 5, 2024
@intellimedhu
Copy link
Author

This solved the problem, thank you!

That's great!

It looks like this is a problem with our LLVM support then. Would you be able to provide a test project we could use to reproduce the problem in order to track it down and fix it?

These changes how much affect the app (size, speed)?

Not compiling with LLVM can make the app slightly smaller (LLVM typically produces more code) although also slightly slower. Depending on the app, the slowness can range from impossible to measure to a noticeable delay, in particular for apps that use a lot of math in C# (for instances games). Most UI apps won't see any difference whatsoever though. If your app feels responsive as usual, then you're fine performance-wise.

I created a test project and invited you.

But I also found out what causes the problem.
In my solution I have 2 projects (maui and a simple class library), if the class library contains the NotificationHubs nuget (and the maui project doesn't), then it throws the exception. But if there's only one project, it works fine.

@rolfbjarne
Copy link
Member

But I also found out what causes the problem.
In my solution I have 2 projects (maui and a simple class library), if the class library contains the NotificationHubs nuget (and the maui project doesn't), then it throws the exception. But if there's only one project, it works fine.

That's interesting.

Can you get an MSBuild binlog for a build that works, and one that doesn't?

@intellimedhu
Copy link
Author

But I also found out what causes the problem.
In my solution I have 2 projects (maui and a simple class library), if the class library contains the NotificationHubs nuget (and the maui project doesn't), then it throws the exception. But if there's only one project, it works fine.

That's interesting.

Can you get an MSBuild binlog for a build that works, and one that doesn't?

I uploaded the two binlog to the test repo.

@Zack-G-I-T
Copy link

Zack-G-I-T commented Oct 2, 2024

We have a class library that uses the Microsoft.Azure.NotificationHubs which our maui app references. The notifications work in debug, and when releasing the app using Ad-hoc to firebase. However when the same code is uploaded to TestFlight using AppStoreConnect as distribution, we get nothing. I tried disabling the linker and enabling the interpreter but no luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants