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

Created on 16 Feb 2020  路  25Comments  路  Source: Azure/azure-functions-host

As discussed in https://github.com/Azure/azure-functions-vs-build-sdk/issues/287 I get the following error messages when deploying an Azure Function:

2>Moving file from "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\ErrorExample.pdb" to "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\bin\ErrorExample.pdb".
2>Microsoft.NET.Sdk.Functions.Generator.dll "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\bin\ErrorExample.dll " "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\ " "False "
2>Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\bin" "C:\Users\z002m76a\Desktop\ErrorExample\ErrorExample\obj\Release\netcoreapp3.1\PubTmp\Out\bin\extensions.json"
2>    Could not evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format.
2>    Could not evaluate 'Microsoft.Azure.Cosmos.ServiceInterop.dll' for extension metadata. Exception message: Bad IL format.

Please find in the following my .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.6.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

The function itself comes directly from the template generator:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace ErrorExample
{
    public static class Function
    {
        [FunctionName("Function")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

host.json looks the following:

{
    "version": "2.0"
}

I'm running

Microsoft Visual Studio Professional 2019
Version 16.4.4
VisualStudio.16.Release/16.4.4+29728.190
Microsoft .NET Framework
Version 4.8.03761

Installed Version: Professional

Visual C++ 2019   00435-60000-00000-AA544
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.4.460.23317
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   16.4.460.23317
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.4.460.23317
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.4.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.4.460.23317
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.4.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

ConfigurationTransform   1.3
Automatically transform app.config during build process. Once the transformation is set, it will run on other build machines without the extension.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GitHub.VisualStudio   2.10.8.8132
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IncrediBuild Build Acceleration   1.5.0.10
IncrediBuild effectively reduces compilation and development times by up to 90%.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure HDInsight Azure Node   2.4.5000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.4.5000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   16.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.4.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.21016.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.0.87+gbb515bf382
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NuGet Package Manager   5.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio   16.0.29417.02
Microsoft Office Developer Tools for Visual Studio

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61912.09160
Microsoft SQL Server Data Tools

Syntax Visualizer   1.0
An extension for visualizing Roslyn SyntaxTrees.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.11031.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6   16.4.0-beta.19556.5+e7597deb7042710a7142bdccabd6f92b0840d354
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions (Preview)   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Most helpful comment

We see something very similar but because they are only warnings the publishing seems to go ahead without issue:

C:\Users\developer\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.4\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning :     Could not 
evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format. [C:\Users\developer\Documents\GitHub\Seymour\src\Seymour.Api.Internal\Seymour.Api.Internal.fsproj]
C:\Users\developer\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.4\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning :     Could not 
evaluate 'Microsoft.Azure.Cosmos.ServiceInterop.dll' for extension metadata. Exception message: Bad IL format. [C:\Users\developer\Documents\GitHub\Seymour\src\Seymour.Api.Internal\Seymour.Api.Internal.fsproj]

All 25 comments

Any word on this? I'm getting these errors only when publishing to Azure. The code runs fine locally. Seriously need a workaround or a fix, or my entire claim to my company that serverless services is the way to go for what we are doing is out the window.

We see something very similar but because they are only warnings the publishing seems to go ahead without issue:

C:\Users\developer\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.4\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning :     Could not 
evaluate 'Cosmos.CRTCompat.dll' for extension metadata. Exception message: Bad IL format. [C:\Users\developer\Documents\GitHub\Seymour\src\Seymour.Api.Internal\Seymour.Api.Internal.fsproj]
C:\Users\developer\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.4\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning :     Could not 
evaluate 'Microsoft.Azure.Cosmos.ServiceInterop.dll' for extension metadata. Exception message: Bad IL format. [C:\Users\developer\Documents\GitHub\Seymour\src\Seymour.Api.Internal\Seymour.Api.Internal.fsproj]

Could you please provide an update on the reported issue? Thanks in advance.

I've succeed and solved the issue by changing the target framework for the project to .NET 2.2
Right click your project > Properties > Target Framework: > .NET Core 2.2 > Save

Going back to .NET Core 2.2 is not an option for me, as it breaks my sources :-(

Hello Microsoft! Anybody working on this topic? At least performing the "Triage"?

@soninaren can you support here? I created this issue on your request https://github.com/Azure/azure-functions-vs-build-sdk/issues/287#issuecomment-586504924

@RufusJWB Thank you for posting the issue. I will try to reproduce this and post an update.
cc: @brettsam

I see the same issue once I pulled in Cosmos into my function.

@soninaren any update on this topic?

any update on this topic...? We're getting the same exact message with a build of an Azure Function using .NET Core 3.1. Going back to .NET Core 2 is maybe possible, but a really bad option for us.

Do you have TreatWarningsAsErrors = true? My repro is showing these as Warnings. But I wonder if we should just make them Messages or explicitly ignore this exception.

Another thing I'll need to investigate -- why does a dotnet build work here but a dotnet publish doesn't?

These are likely platform-specific assemblies (which is why we can't load them for evaluation) -- but should they be here or in the runtimes directory?

I do not have TreatWarningsAsErrors = true turned on. Yes - this worked with a "dotnet build" step, but fails on a "dotnet publish" step (most of the time). Occasionally when the build server runs, it does work, then the next time it fails. Both times I'll see the errors about "Bad IL Format" in the log, but sometimes it succeeds and sometimes it fails...

I do not have TreatWarningsAsErrors = true turned on, but my experience is, that un-resolved warnings later lead to strange errors. That's why I always try to fix all Warnings. If this really is not the case here, the log level should not be Warning but Message/Info.

Relevant log section:

\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. [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(63,5): warning :     Could not evaluate 'Microsoft.Azure.Documents.ServiceInterop.dll' for extension metadata. Exception message: Bad IL format. [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018: The "RemoveRuntimeDependencies" task failed unexpectedly. [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018: System.UnauthorizedAccessException: Access to the path 'D:\_tfs_data\agent\_work\4\a\FusionService.Core\bin\Microsoft.AspNetCore.Authentication.Abstractions.dll' is denied. [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018:    at System.IO.FileSystem.DeleteFile(String fullPath) [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018:    at System.IO.File.Delete(String path) [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018:    at Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.BuildTasks.RemoveRuntimeDependencies.Execute() [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]
\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.5\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(35,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\_tfs_data\agent\_work\4\s\FusionService.Core\FusionService.Core\FusionService.MessageProcessor.DataPacketReceiver\FusionService.MessageProcessor.DataPacketReceiver.csproj]

Chiming in to say this issue is relevant for me as well. Would like to get it solved.

Hey @brettsam -- any update on this...? It's been two weeks since you said you'd investigate and I'm still dead in the water and can't build and publish my function... Still lots of people saying they are having this problem.

Hi, I am experiencing the same problem too.

I've done some investigating. Just have a little more validation to do before the fixes come. In short, there were two things that were confusing here:

  1. Why did this only happen on publish? Turns out that the functions sdk only copies all DLLs and PDBs to the /bin folder on publish -- so this file was never copied during build.
  2. Why didn't this throw if it wasn't in the /bin folder when you hit F5 locally? Isn't it needed? @ealsur filled me in -- this is a native dependency that can improve query performance. If not there, you'll get a perf hit, but things won't blow up.

There'll be a fix to ignore BadImageFormatException in the ExtensionsMetadataGenerator and one to also copy DLLs/PDBs to /bin upon building. The second part is to make things consistent -- you shouldn't be surprised by warnings like this during a publish only.

That makes sense - thanks for the update! Any estimate on when we might get this fix or what packages will actually be updated for this fix? Will it be an update to the Microsoft.NET.Sdk.Functions package?

The fix is now in -- I'll work on getting this released to nuget on Monday. Yes it'll be an update to Microsoft.NET.Sdk.Functions.

I am facing same issue while publishing my azure function from visual studio 2019

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

Please help how to solve this..

Please try the latest versions of Microsoft.Net.Sdk.Functions. Release notes:

I can confirm, that it is working. Thank you for that. But I still get publishing errors. I'll open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alaatm picture alaatm  路  4Comments

christopheranderson picture christopheranderson  路  4Comments

paulbatum picture paulbatum  路  4Comments

shibayan picture shibayan  路  3Comments

silencev picture silencev  路  4Comments