How can I resolve this NewtonSoft version conflict? - azure

I'm working on an Azure function. I'm using Microsoft.Azure.Devices.Shared, which requires NewtonSoft v11, so I've implemented some manual binding redirects with the app domain which seems to be working (see below). But somehow, there is a hard reference to the WebJob app domain that NewtonSoft is conflicting with if I'm reading the log below correctly:
2018-05-21T22:03:03.824 [Info] Exception:
[A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadNeither' in a byte array.
My Newtonsoft v11 dll is in the function's bin directory and is referenced there like so:
#r "bin\Newtonsoft.Json.dll"
There is actual code in the function that works correctly in the function:
dynamic eventHubMessage =
JsonConvert.DeserializeObject<JObject>(myEventHubMessage);
But when it hits this line:
CRSLTwinData twinData = IotHubProxy.GetTwinData(hubDeviceId);
It throws the exception. The reference to M.A.D.Shared and Newtonsoft 11 is therein.
I've tried everything I can to get the function to use the 11 version of the dll, but something is obviously out of whack.
UPDATE: we tried redirecting to 9 instead and got this:
2018-05-22T13:24:48.336 [Info] Exception: [A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadFrom' at location 'D:\local\Temporary ASP.NET
Files\root\e801054b\3f30c00f\assembly\dl3\e5381214\00f64e9a_9af1d301\Newtonsoft.Json.dll'.
Then we tried redirect to 10 and got this :):
2018-05-22T14:16:14.509 [Info] Exception:
[A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadFrom' at location 'D:\local\Temporary ASP.NET
Files\root\e801054b\3f30c00f\assembly\dl3\e5381214\00f64e9a_9af1d301\Newtonsoft.Json.dll'.

I presume you are using azure function 1.0 which has known assembly resolution problem.
Since webjob use strict version number of Newtonsoft json, what I have done in my project is to downgrade all mine to inline with the sdk's

Use Microsoft.NET.Sdk.Functions version 1.0.13, which consumes Newtonsoft.Json 10.0.3

Related

TypeLoadException: Could not load type 'System.Net.Http.SocketsHttpHandler

Is there any way that i can overcome this error:
System.TypeInitializationException: 'The type initializer for 'Azure.Core.Pipeline.HttpClientTransport' threw an exception.'
TypeLoadException: Could not load type 'System.Net.Http.SocketsHttpHandler' from assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The Framework that i was using is 4.7 and i was getting this error, when i try to get this value. SmsClient smsClient = new SmsClient(connectionString);
Here i've tried Bind Redirect to the latest version & the particular Version mentioned in the error 4.0.0.0 .
But still i was getting the same. Any suggestions for this...

How to resolve following issue : 'Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' error

getting this issue for crystal report: 'System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'...i have added log4net.dll on azure server via filezilla...
what steps to be done to resolve this issue

Is there any solution for not a file URL problem?

I get this error while i run my application:
{System.TypeLoadException: Could not load type of field due to: Could not load file or assembly 'System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
Any solution for this exception?

Is it possible to reference external assembly with native dependencies in Azure function?

I'm getting following exception when doing aforementioned:
2017-12-10T12:40:39.771 Exception during runtime resolution of assembly 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null':
'System.IO.FileLoadException: Could not load file or assembly 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019)
File name: 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null' ---> System.IO.FileLoadException: Attempt to load an unverifiable executable with fixups
Is there a location that Azure Function runtime looks for dependencies (like Sys32/Inetsrv in Windows)?

Can you use project.json in an azure service fabric project?

I'm trying to use project.json to make managing packages easier in a Service Fabric project.
However it is failing and I think it is due to not including ServiceFabricServiceModel.dll in the services. I can see the dll in the nuget packages in C:\Users\nick.nuget\packages\Microsoft.ServiceFabric.Actors\2.0.135\lib\net45, but the nuspec file does not reference it.
There are quite a few errors when trying to deploy.
For example
Exception thrown during async task execution
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Microsoft.ServiceFabric.Services.Common.FabricServiceConfigSection.Initialize()
at Microsoft.ServiceFabric.Services.Remoting.FabricTransport.FabricTransportServiceRemotingProviderAttribute.CreateServiceRemotingListener(ServiceContext serviceContext, IService service)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<OpenCommunicationListenersAsync>d__1b.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 Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<System.Fabric.IStatefulServiceReplica.ChangeRoleAsync>d__5.MoveNext()
=== Pre-bind state information ===
LOG: DisplayName = ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/SfDevCluster/Data/_App/_Node_1/SceneSkopePlatformType_App0/ServiceRegistrationServicePkg.Code.1.1.13 (2016-04-05 16.10.16Z)/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.ServiceFabric.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SfDevCluster\Data\_App\_Node_1\SceneSkopePlatformType_App0\ServiceRegistrationServicePkg.Code.1.1.13 (2016-04-05 16.10.16Z)\ServiceRegistrationService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
This is a breaking change how dotnet cli handles not listed assemblies in nuget packages. For "old style" projects VS2015 copies this assembly to the project output, but the dotnet cli does not.
Until it's fixed, you can either wrap the assembly or copy it to the output in a postpublish step.
The assembly is downloaded to:
%userprofile%.nuget\packages\Microsoft.ServiceFabric.Services\2.0.135\lib\net45
MSFT solved this in the latest nuget package version 2.1.150

Resources