Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 119 forks source link

[BUG] Microsoft.Azure.NotificationHubs Version=4.2.0 #316

Open SanandABB opened 2 months ago

SanandABB commented 2 months ago

Describe the bug We are getting errors while trying to update the Microsoft.Azure.NotificationHubs' Version='4.2.0'. According to NuGet Gallery | Microsoft.Azure.NotificationHubs 4.2.0 the dependency in .NETStandard 2.1 is for package Microsoft.Extensions.Caching.Memory with version (greater or = 6.0.1) but at runtime version 6.0.0 is expected.

Exception or Stack Trace Error Message: System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'Microsoft.Extensions.Caching.Memory, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. Source=Microsoft.Azure.NotificationHubs StackTrace: at Microsoft.Azure.NotificationHubs.Auth.TokenProvider..ctor(Boolean cacheTokens, TimeSpan cacheExpirationTime) at Microsoft.Azure.NotificationHubs.Auth.TokenProvider..ctor(TimeSpan cacheExpirationTime) at Microsoft.Azure.NotificationHubs.Auth.SharedAccessSignatureTokenProvider..ctor(String connectionString) at Microsoft.Azure.NotificationHubs.Auth.SharedAccessSignatureTokenProvider.CreateSharedAccessSignatureTokenProvider(String connectionString) at Microsoft.Azure.NotificationHubs.NotificationHubClient..ctor(String connectionString, String notificationHubPath, NotificationHubSettings settings) at Microsoft.Azure.NotificationHubs.NotificationHubClient..ctor(String connectionString, String notificationHubPath) at Microsoft.Azure.NotificationHubs.NotificationHubClient.CreateClientFromConnectionString(String connectionString, String notificationHubPath)

To Reproduce Step 1 - Update Microsoft.Azure.NotificationHubs to Version=4.2.0 in Azure function version 3. Step 2 - Update Microsoft.Extensions.Caching.Memory to version 6.0.1 in the same Azure function Step 3 - Call the following method available in Microsoft.Azure.NotificationHubs: NotificationHubClient.CreateClientFromConnectionString(azureNotificationHubConnectionString, azureNotificationHubName).

Code Snippet notificationHub = NotificationHubClient.CreateClientFromConnectionString(azureNotificationHubConnectionString, azureNotificationHubName);

Expected behavior Notification hub client instance created; No dependency to Microsoft.Extensions.Caching.Memory to version 6.0.0

Screenshots Error 1 Error 2

Setup (please complete the following information): Visual Studio 2019

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

marstr commented 2 months ago

Hi @SanandABB,

Thanks for reaching out. I'm working on repro'ing this bug independently. Can you give me more information about the version of .NET that you're using to host the Azure Functions instance where you are seeing this issue?

As an aside, I've confirmed that using ILSpy, only the major version of the dependency is being rendered. So despite having 6.0.1, ILSpy still reports 6.0.0.0.

SanandABB commented 2 months ago

From: Martin Strobel @.> Sent: 25 April 2024 02:43 AM To: Azure/azure-notificationhubs-dotnet @.> Cc: Sanand IV @.>; Mention @.> Subject: Re: [Azure/azure-notificationhubs-dotnet] [BUG] Microsoft.Azure.NotificationHubs Version=4.2.0 (Issue #316)

BeSecure! This email comes from outside of ABB. Make sure you verify the sender before clicking any links or downloading/opening attachments. If this email looks suspicious, report it by clicking 'Report Phishing' button in Outlook or raising a ticket on MyIS.

Hi @SanandABBhttps://urldefense.com/v3/__https:/github.com/SanandABB__;!!NLW3fF9v!MyGj5kKRhy30l3J-GLM63IVO_NxR8le7xJ7ADxn7Bou2-8MLgM4h9ltbwZSRXaH4ryqirp-Ljtk7uq5w5RMahWQw$,

Thanks for reaching out. I'm working on repro'ing this bug independently. Can you give me more information about the version of .NET that you're using to host the Azure Functions instance where you are seeing this issue?

As an aside, I've confirmed that using ILSpy, only the major version of the dependency is being rendered. So despite having 6.0.1, ILSpy still reports 6.0.0.0.

- Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/Azure/azure-notificationhubs-dotnet/issues/316*issuecomment-2075853601__;Iw!!NLW3fF9v!MyGj5kKRhy30l3J-GLM63IVO_NxR8le7xJ7ADxn7Bou2-8MLgM4h9ltbwZSRXaH4ryqirp-Ljtk7uq5w5Z2eTnX5$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BHYXZQEACVUA5E2YNUAKYJDY7AN43AVCNFSM6AAAAABGEAQKNOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZVHA2TGNRQGE__;!!NLW3fF9v!MyGj5kKRhy30l3J-GLM63IVO_NxR8le7xJ7ADxn7Bou2-8MLgM4h9ltbwZSRXaH4ryqirp-Ljtk7uq5w5fAQQWZM$. You are receiving this because you were mentioned.Message ID: @.**@.>>

austinlau commented 1 month ago

I have the similar issue and find out that it may be related to "assembly binding redirect" in App.config or Web.config to map the version from 6.0.0.0 to 6.0.0.1. If the bindingRedirect is manually removed, the Error "Could not load file or assembly 'Microsoft.Extensions.Caching.Memory, Version=6.0.0.0" will throw.

Usually the bindingRedirect is generated automatically. But in some rare cases it can't. For example, the reference "Microsoft.Extensions.Caching.Memory" is removed under the Project References in Visual Studio.

Not sure if it is the same case of @SanandABB. My fix is to uninstall both "Microsoft.Azure.NotificationHubs" and "Microsoft.Extensions.Caching.Memory" in NuGet and then install back the NotificationHubs. Then confirm the bindingRedirect is exist in Web.config or App.config.

<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Caching.Memory" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
hidayatmeman62 commented 1 month ago

I'm also getting the same issue and I did tried @austinlau solution but didnt work. Below are the framework and package versions .NET Framework 4.7.1 Microsoft.NET.Sdk.Functions 1.0.31 Microsoft.Azure.WebJobs 2.3.0 Microsoft.Azure.NotificationHubs 4.2.0 Microsoft.Extensions.Caching.Memory 6.0.1

ANS-334-T-TrinhDinhThoan commented 1 month ago

I have same issue, I had clean project, reinstall nuget, but not woking. Could it be related to the structure of the project? As @austinlau said above, the web.config file will automatically add bindingRedirect, but in my case, I don't see any bindingRedirect, and I added it manually but it didn't work. image image image

marstr commented 1 month ago

Howdy folks - I've accepted a new role and am no longer working on the ANH product. I'm going to unassign myself, but I'll send some emails internally to get this issue attention.

TAbbott117 commented 3 weeks ago

Hi @SanandABB !

Hope all is well. It is possible that the issue could be related to your Azure Functions configuration. I have found some other examples of similar dependency resolution errors involving Azure Functions on StackOverflow - [here is an example of such an issue]. (https://stackoverflow.com/questions/64809716/could-not-load-file-or-assembly-microsoft-extensions-configuration-abstractions)

One possible workaround seems to be updating the Azure Function version to v4. Would that be something you could try and report back the results?

Thanks!

leonardbarbu commented 3 weeks ago

You can solve Azure NH 4.2.0 working by having all the Microsoft.Extensions.* packages to 6.0.0. Here is my packages.config (.NET Framework 4.8 project).

<package id="Microsoft.Azure.NotificationHubs" version="4.2.0" targetFramework="net48" />
<package id="Microsoft.Extensions.Caching.Abstractions" version="6.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.Caching.Memory" version="6.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="6.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="6.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.Options" version="6.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.Primitives" version="6.0.0" targetFramework="net48" />

For this, you need to force to install Microsoft.Extensions.Caching.Memory to 6.0.0. You can do this by this NuGet Package Manager Console command:

Install-Package Microsoft.Extensions.Caching.Memory -IgnoreDependencies -version 6.0.0

tomhannigan8 commented 1 week ago

These possible solutions mentioned above haven't worked for me. I'm unable to ignore dependencies in NuGet Package Manager. Planning to update Azure Function to version 4 but any other ways to fix this issue would be of great help. Thank you