none
Fucntion sdk 1.0.29 - with Dependency injection and Cosmos db : Exception message: Bad IL format, Works locally but Fails to publish with Error : RRS feed

  • Question

  • Works Locally But,

    when we publish the build output fails and gives below error: 

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

     

    Csproj, i have some references of shared proj, and packages.

    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <AzureFunctionsVersion>v2</AzureFunctionsVersion>
      </PropertyGroup>

     <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.12" />
        <PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="2.0.0-preview-009470001-1371" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />  
        <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />  
      </ItemGroup>

     <ItemGroup>
        <ProjectReference Include="..\src\Jupiter.DAL\Jupiter.DAL.csproj" />
        <ProjectReference Include="..\src\Jupiter.Services\Jupiter.Services.csproj" />
      </ItemGroup>
      <Import Project="..\DocumentDBShared\DocumentDBShared.projitems" Label="Shared" />

    Startup looks something like this :                      

    using Microsoft.Azure.Cosmos;
    using Microsoft.Azure.Cosmos.Fluent;
    using Microsoft.Azure.Functions.Extensions.DependencyInjection;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.Configuration.AzureAppConfiguration;
    using Microsoft.Extensions.DependencyInjection;
    using Newtonsoft.Json.Linq;
    using System;
    using System.Threading.Tasks;

    [assembly: FunctionsStartup(typeof(Startup))]

    namespace Jupiter.Automation
    {

        public class Startup : FunctionsStartup
        {   

            private static IConfigurationRoot configuration = new ConfigurationBuilder().
                                                             AddAzureAppConfiguration("...EndpointHere").
                                                            Build();

            public override void Configure(IFunctionsHostBuilder builder)
            {
                var identityConfig = configuration["config"];

                IConfigurationSection configurationSection = configuration.GetSection("");
                builder.Services.AddSingleton<CosmosClient>(Initialize(configurationSection));

                builder.Services.AddIdentity<KradleUser, CosmosIdentityRole>()
                    .AddDefaultTokenProviders()
                    .AddDocumentDbStores(options =>
                    {
                        options.ContainerName = (JObject.Parse(configurationSection.Value) as dynamic).ContainerNameAuth;
                        options.DatabaseName = (JObject.Parse(configurationSection.Value) as dynamic).DatabaseName;
                    }); 


                // Auth
                builder.Services.AddSingleton<ICosmosDbService<KAccount>>(CosmosClientInitializer<KAccount>.Initialize(configurationSection).GetAwaiter().GetResult());
                builder.Services.AddSingleton<IKAccountService, KradleAccountService>();



            }
            public static CosmosClient Initialize(IConfigurationSection configurationSection)
            {
                string account = (JObject.Parse(configurationSection.Value) as dynamic).Account;
                string key = (JObject.Parse(configurationSection.Value) as dynamic).Key;

                CosmosClientBuilder clientBuilder = new CosmosClientBuilder(account, key);
                CosmosClient client = clientBuilder.WithConnectionModeDirect().Build();

                return client;
            }
        }

        public static class CosmosClientInitializer<T> where T : class
        {
            public static async Task<CosmosDbService<T>> Initialize(IConfigurationSection configurationSection, KContainer container = KContainer.Auth)
            {
                string databaseName = (JObject.Parse(configurationSection.Value) as dynamic).DatabaseName;
                string containerName = GetContainerName(configurationSection, container);
                string account = (JObject.Parse(configurationSection.Value) as dynamic).Account;
                string key = (JObject.Parse(configurationSection.Value) as dynamic).Key;

                CosmosClientBuilder clientBuilder = new CosmosClientBuilder(account, key);

                CosmosClient client = clientBuilder.WithConnectionModeDirect().Build();

                CosmosDbService<T> cosmosDbService = new CosmosDbService<T>(client, databaseName, containerName);

                return cosmosDbService;
            }

        }

    AzureFunction 

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Extensions.Logging;
    using Jupiter.Services.Interfaces;
    using System.Linq;


    namespace Jupiter.Automation
    {
        public class TestFunction
        {
            private readonly IKAccountService _kaAccountService;
           
            public TestFunction(IKAccountService kAccountService )
            {
                _kaAccountService = kAccountService;

            }
               
        
            [FunctionName("TestFunction")]
            public  async Task Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer
                                        , ILogger log)
            {
                //return;
                if (log == null)
                {
                    throw new ArgumentNullException(nameof(log));
                }


                log.LogInformation($"Payment timer trigger function executed at: {DateTime.Now}...Live now Days "); // Version = 0.8.070. Function is disabled for now.");

              
                try
                {              
                                   
                        var currentUTC = DateTime.UtcNow;
                    
                
                        var accounts = await _kaAccountService.GetAccountsForMonthlyPayments(currentUTC);
                       

                      }
                    catch (Exception ex)
                    {
                        log.LogError($"Test: Exception:{ex.Message}, StackTrace:{ex.StackTrace}");

                    }
            }
        }
    }


    • Edited by Aditi Pithwa Tuesday, September 17, 2019 1:30 AM
    Tuesday, September 17, 2019 1:28 AM

All replies

  • Looks like the same issue is being discussed on this issue as well.

    Many of responses talk about downgrading Microsoft.NET.Sdk.Functions to 1.0.24 as a workaround. Could you try that to see if that solves things?

    Tuesday, September 17, 2019 4:53 PM
    Moderator
  • Thanks for the reply, I had already tried that link and saw the solution, but 1.0.24 does not support dependency injection, so I am inclined to use sdk 1.0.29

    Wednesday, September 18, 2019 10:22 PM
  • Looks like others on that issue are having the same problem with downgrading but don't think there is a workaround. I will try to escalate further internally and will post any updates here.
    Tuesday, October 1, 2019 5:54 AM
    Moderator
  • Hi PramodValavala,

    Its really a problem for us, blocking our development.

    We are eagerly awaiting the resolution from Microsoft.

    Thank you in advance

    Wednesday, October 2, 2019 1:55 AM