In my mvc application I'm calling one async method, on button click, which will register device into iot hub.
The code works fine in the console app but is giving an issue in the mvc app.
error:
The type initializer for 'Microsoft.Azure.Devices.HttpClientHelper' threw an exception.
Inner exception :
Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Newtonsoft.Json packages is already installed into project 10.0.3 version code
public async Task<ActionResult> AddDeviceAsync()
{
Device device;
try
{
connectionString = ConfigurationManager.AppSettings["DefaultIoTHubConnection"];
registryManager = RegistryManager.CreateFromConnectionString(connectionString);
List<string> collection = new List<string>();
for (int i = 0; i < 4; i++)
{
collection.Add("dummy_device_" + i);
}
foreach (var deviceId in collection)
{
try
{
// register device into IoT hub
device = await registryManager.AddDeviceAsync(new Device(deviceId)); // getting exception here
this problem arises when the CLR executes compiled code and it is not able to find an assembly in the app domain.
The idea here is that the code you are executing was compiled by referencing the version 6.0.0.0 of Newtonsoft.Json, but at runtime you are executing that code in an application domain where the referenced assembly is not available (or the referenced version of the assembly is not available).
Does your asp.net mvc project reference the Newtonsoft.Json nuget package ? What version of the package are you referencing ?
User contributions licensed under CC BY-SA 3.0