Azure function error: Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=7.0.0.0'?

谁说我不能喝 提交于 2019-12-13 03:34:57

问题


I m doing a azure function and testing it locally where it will add some data to Dyanmcis CRM. When I run function it throw this error:

Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Please note my code uses Microsoft.Xrm.Client(version 7) and it has Microsoft.Xrm.Sdk (version 8.1.0.235).

Please help.


回答1:


The problem is due to the missing assembly redirect. You can see exactly which assembly redirect is needed by adding the Microsoft.CrmSdk.CoreAssemblies NuGet package to a normal .Net project and looking at the generated binding redirect statements added to app.config.

Currently Azure Functions do not support setting assembly redirects, so it has to be done in code. I solved this problem by using the code from this blog post: How to fix the assembly binding redirect problem in Azure Functions

With that code, local.settings.json looks like this:

"Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": "",
    "BindingRedirects": "[ { \"ShortName\": \"Microsoft.Xrm.Sdk\", \"RedirectToVersion\": \"8.0.0.0\", \"PublicKeyToken\": \"31bf3856ad364e35\" } ]"
}

and in Application settings in the Azure portal:

[ { "ShortName": "Microsoft.Xrm.Sdk", "RedirectToVersion": "8.0.0.0", "PublicKeyToken": "31bf3856ad364e35" } ]


来源:https://stackoverflow.com/questions/49021176/azure-function-error-could-not-load-file-or-assembly-microsoft-xrm-sdk-versio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!