azure-data-explorerkusto-clientpackage-dependencies

KustoIngestFactory fails to load dependent assembly at runtime with FileNotFoundException


We have a .NET 6 Azure Function App that currently uses the Microsoft.Azure.Kusto.Data (v12.2.1) package to write records to kusto using admin commands. I am attempting to replace these admin commands with streaming ingestion of data. I installed the Microsoft.Azure.Kusto.Ingest package, and made the required changes, however when I attempt to test my changes locally, it fails at this line:

kustoIngestProvider = KustoIngestFactory.CreateStreamingIngestClient(kustoIngestServer);

with this exception:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Kusto.Ingest.KustoIngestFactory' threw an exception.
  Source=Kusto.Ingest
  StackTrace:
   at Kusto.Ingest.KustoIngestFactory.CreateStreamingIngestClient(String connectionString, Boolean autoCorrectEndpoint)
   at WorkloadReview.Utilities.KustoClient..ctor(ILogger`1 logger, String kustoServer, String kustoIngestServer, String tenant, String msiClientId) in C:\src\AzureCXP-CXObserve-BE\src\Common\WorkloadReview\KustoClient.cs:line 63
   at ReviewManagement.Utilities.ReviewKustoClient..ctor(ILogger`1 logger) in C:\src\AzureCXP-CXObserve-BE\src\ReviewManagement\ReviewManagement\Utilities\ReviewKustoClient.cs:line 28
   at DryIoc.Scope.TryGetOrAdd(ImMap`1 items, Int32 id, CreateScopedValue createValue, Int32 disposalOrder)
   at DryIoc.Scope.GetOrAdd(Int32 id, CreateScopedValue createValue, Int32 disposalOrder)
   at DryIoc.Scope.TryGetOrAdd(ImMap`1 items, Int32 id, CreateScopedValue createValue, Int32 disposalOrder)
   at DryIoc.Scope.GetOrAdd(Int32 id, CreateScopedValue createValue, Int32 disposalOrder)
   at DryIoc.Container.ResolveAndCacheDefaultFactoryDelegate(Type serviceType, IfUnresolved ifUnresolved)
   at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, IfUnresolved ifUnresolved)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance[T](IServiceProvider serviceProvider)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize()
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__18.MoveNext()

  This exception was originally thrown at this call stack:

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

This doesn't make sense, as I have looked and the System.Diagnostics.DiagnosticSource 8.0.0 package is installed in my nuget cache and the assembly is being copied to the bin directory of my project just as expected. Also, lots of other packages are dependent on this assembly (includeing Microsoft.Azure.Kusto.Data) and none of them are failing. I've tried building and running this on two completely separate machines with the same result, so its not an issue with my dev environment.

Update:

I tried downgrading to 11.3.5 for both the Microsoft.Azure.Kusto.Data and Microsoft.Azure.Kusto.Ingest packages and I'm no longer getting the FileNotFoundException during type initialization, so this looks like a bug in the latest version(s) of the Ingest package.


Solution

  • Found the answer here.

    Just needed to add this to the project file:

    <PropertyGroup>
        <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    </PropertyGroup>