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

Exception trying to load Newtonsoft.Json Version 10 when calling CreateOrUpdateInstallationAsync #27

Closed
Architekt909 opened this issue Feb 9, 2019 · 3 comments

Comments

@Architekt909
Copy link

Architekt909 commented Feb 9, 2019

I'm using version 3.0.1 in my Azure Function project. Every time I call CreateOrUpdateInstallationAsync I get an exception saying that it's trying to load Newtonsoft.Json v10. I have Newtonsoft.Json version 11.0.2 installed (and require it, I can't use a lower version). I'm not sure why I'd be getting this, since the NotificationHubs package says it requires a version of the Json lib >=10.0.3. Here's the full exception details:

Edit1: I have no idea why it's bolding some chunks, tried editing it to remove it, couldn't figure it out
Edit 2: I tried downgrading package versions, and kept getting this exact same exception until I got down to version 1.0.9. This is the latest version I'm able to use without getting an exception.

`System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at Microsoft.Azure.NotificationHubs.Installation.ToJson()
at Microsoft.Azure.NotificationHubs.NotificationHubClient.d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at BurnableCloud.Shared.Notifications.d__12.MoveNext()

Pre-bind state information
LOG: DisplayName = Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///C:/Users/myusernamecleverlyremoved/AppData/Local/AzureFunctionsTools/Releases/1.6.0/cli/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Azure.NotificationHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\myusernamecleverlyremoved\AppData\Local\AzureFunctionsTools\Releases\1.6.0\cli\func.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: The same bind was seen before, and was failed with hr = 0x80070002.`

@Architekt909
Copy link
Author

I can 100% repro this using a very tiny function app. The only thing in this project is Newtonsoft.JSON 11.0.2, Microsoft.NET.Sdk.Functions 1.0.24, and Microsoft.Azure.NotificationHubs 3.0.1. Call the function (make sure to use a valid connection string and path, I removed mine for security reasons) and you'll trip the exception with the error I posted above.

I don't know if this is because I'm using Functions runtime v1 or not, but I can't upgrade to v2 due to Microsoft.SqlServer.Management.AlwaysEncrypted.AzureKeyVaultProvider not being compatible yet (an issue raised that's been in progress for a very long time at this point).

TestNotifications.zip

@brannon
Copy link
Contributor

brannon commented Mar 6, 2019

@Architekt909 thanks for reporting this. Azure Functions v1 does not support binding redirects, and so unfortunately .NET will not automatically load Newtonsoft.Json 11.0.2 instead of 10.0.3. You can read more about the issue in this bug: Azure/azure-functions-host#992

The assembly loading issue should be fixed in Azure Functions v2, but it sounds like you aren't able to use v2 yet.

At this time we don't have a solution for resolving the assembly loading issue with Newtonsoft.Json and Azure Functions v1.

@Architekt909
Copy link
Author

Is there any problem with me using an older version? 1.0.9 works for me, and I seem to be getting push messages on both Android and iOS.

@brannon brannon closed this as completed Jul 31, 2019
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

2 participants