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

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

Open
SanandABB opened this issue Apr 12, 2024 · 10 comments
Open

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

SanandABB opened this issue Apr 12, 2024 · 10 comments

Comments

@SanandABB
Copy link

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

  • Version of the Library used - 4.2.0

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

  • [OK ] Bug Description Added
  • [OK ] Repro Steps Added
  • [ OK] Setup information Added
@marstr marstr self-assigned this Apr 24, 2024
@marstr
Copy link
Member

marstr commented Apr 24, 2024

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
Copy link
Author

SanandABB commented Apr 24, 2024 via email

@austinlau
Copy link

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
Copy link

hidayatmeman62 commented Jun 4, 2024

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
Copy link

ANS-334-T-TrinhDinhThoan commented Jun 5, 2024

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
Copy link
Member

marstr commented Jun 5, 2024

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.

@marstr marstr removed their assignment Jun 5, 2024
@TAbbott117
Copy link

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
Copy link

leonardbarbu commented Jun 12, 2024

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
Copy link

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

@dakipmyster
Copy link

@TAbbott117

The most upvoted suggestions are to downgrade Microsoft.Extensions.* to a 3.1.X version. When I attempt to do so, It also wants me to downgrade the Microsoft.Azure.NotificationHubs version to 4.1.0 which I do not want to do.

Other suggestions on this thread have not helped me out either. Not sure if anyone else as another work around idea. I am a bit lost on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants