Could not evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format

Viewed 3757

I'm getting below warning while publishing azure function in Visual Studio 2019.

Could not evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format. Could not evaluate 'Microsoft.Azure.Documents.ServiceInterop.dll' for extension metadata. Exception message: Bad IL format.

I tried the same in a blank project but the same warning coming.

Same issue I can see with VS Code

C:\Users\pankaj.ra.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning : Could not evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format.

My function proj file

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.1.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.5" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
1 Answers

Because you get the same error in a blank project, the problem is hard to troubleshoot. I create a blank function and run it well both in local and azure.

First, clean up all the nuget caches (local & global) and restore everything.

dotnet nuget locals all --clear

Chances are this is because of a processor architecture mismatch: loading 64-bit assemblies when you use 32-bit causes this, for instance.

If your application uses 32-bit components, make sure that it always runs as a 32-bit application.
Make sure that you are not using a component that was created with a different version of the .NET Framework.
Make sure that the file image is a valid managed assembly or module.

And, as far as the first item on the list goes:

If the Platform target property for your application project is set to AnyCPU, the compiled application can be run in either 64-bit or 32-bit mode. When it runs as a 64-bit application, the just-in-time (JIT) compiler produces 64-bit native code. If the application depends on a 32-bit managed or unmanaged component, that component will fail to load in 64-bit mode. To correct this problem, set the project's Platform target property to x86 and recompile.

For more details, you could refer to this article.

Related