excelDna issue with Microsoft.extensions.http version 8.0

50 views
Skip to first unread message

Keith MacCrimmon

unread,
Nov 24, 2025, 4:12:20 PMNov 24
to Excel-DNA
I created a simple exceldna project in .net 8.00  and micosoft.extension.http version 10(latest).  I tried using the iHttpClientFactory: Code is below. The createClient Errors out with : 

'Method not found: 'System.Diagnostics.Metrics.IMeterFactory System.Net.Http.SocketsHttpHandler.get_MeterFactory()'.'

I found a post that said microsoft.extension.http introduces metrics in verion 8. I suspect ExcelDNa is using an earlier version of the library.

Does that makes sense?

thanks

Keith



public class DataFluxAddin:IExcelAddIn
{
    public void AutoOpen()
    {
        var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
       serviceCollection
            .AddHttpClient();
        var serviceProvider = serviceCollection.BuildServiceProvider();
        var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
        var c1 = httpClientFactory.CreateClient();
    }

    public void AutoClose()
    {
       
    }
}

Suki Gill

unread,
Nov 25, 2025, 4:58:24 PMNov 25
to Excel-DNA
I had the same issue a few days ago.

I'm using .Net Core 9 with ExcelDNA 1.9.

HttpClientFactory works fine with all my other projects except for those using Excel DNA.

I had to apply the following work around (hack) as I needed to use HttpClientFactory in ExcelDNA to address another issue I was having.





Govert van Drimmelen

unread,
Nov 26, 2025, 4:16:06 AMNov 26
to Excel-DNA
Hi Keith,

Excel-DNA creates an AssemblyLoadContext for your add-in, and should be loading assemblies according to the .deps.json file of your library.
But for assemblies that are part of the runtime (like System.Net.Http) I think the ALC load will always use the runtime version and not a newer version that you ship.

You might try some diagnostics like this at different places in your code:

using System;
using System.Reflection;
using System.Runtime.Loader;

public static class AssemblyTrace
{
    public static void Dump()
    {
        var asm = typeof(System.Net.Http.HttpClient).Assembly;

        Console.WriteLine("=== System.Net.Http Assembly Info ===");
        Console.WriteLine("FullName:   " + asm.FullName);
        Console.WriteLine("Location:   " + asm.Location);
        Console.WriteLine("From GAC:   " + (asm.GlobalAssemblyCache ? "yes" : "no"));
        Console.WriteLine("LoadCtx:    " + AssemblyLoadContext.GetLoadContext(asm)?.GetType().FullName);
        Console.WriteLine("=====================================");
    }
}

I'd call it in AutoOpen() before your code runs, and also after your code, and see whether you find which version is being loaded from where.
If the assembly in question is not System.Net.Http then try others.

You can also look in the .deps.json file to see what the intended assemblies are.

You're looking for evidence that it loads an old version from the runtime instead of the new version from your add-in output.
If so, your only way forward is to upgrade your runtime target or downgrade that assembly reference.

If that's not what is going on, I think another problem might be that the transitive dependencies don't end up with the right version of the extra assemblies. So your .deps.json is basically inconsistent - the add-in's assembly references end up loading an older version of something. If this is the case, you can try to explicitly add PackageReference to some of the transitive dependencies, forcing the newer version of these.
ChatGPT suggested the code below to explore the loaded versions further (I didn't try it).

-Govert


using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Collections.Generic;

public static class DependencyDiagnostics
{
    // Assemblies whose version must be consistent (transitive closure)
    static readonly string[] InterestPrefixes = new[]
    {
        "Microsoft.Extensions.",
        "System.Diagnostics.DiagnosticSource",
        "System.Diagnostics.Metrics",
        "System.Net.Http",
        "Microsoft.Bcl.AsyncInterfaces"
    };

    public static void Dump()
    {
        Console.WriteLine("=== BEGIN EXCEL-DNA DEPENDENCY DIAGNOSTICS ===");

        var loaded = AppDomain.CurrentDomain.GetAssemblies();
        var relevant = loaded
            .Where(a =>
                InterestPrefixes.Any(p =>
                    a.GetName().Name.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
            .OrderBy(a => a.GetName().Name)
            .ToList();

        foreach (var asm in relevant)
        {
            WriteAsm(asm);
        }

        Console.WriteLine();
        Console.WriteLine("=== VERSION GROUPS ===");
        ReportVersionGroups(relevant);

        Console.WriteLine("=== END EXCEL-DNA DEPENDENCY DIAGNOSTICS ===");
    }

    static void WriteAsm(Assembly asm)
    {
        var name = asm.GetName();
        var ctx = AssemblyLoadContext.GetLoadContext(asm);
        var location = asm.IsDynamic ? "<dynamic>" : (string.IsNullOrEmpty(asm.Location) ? "<unknown>" : asm.Location);

        Console.WriteLine($"{name.Name,-45} {name.Version,-15} {ctx?.GetType().Name,-25} {location}");
    }

    static void ReportVersionGroups(List<Assembly> asms)
    {
        // Group by simple name (Microsoft.Extensions.Http → group)
        var groups = asms.GroupBy(a => a.GetName().Name);

        foreach (var g in groups)
        {
            var versions = g.Select(a => a.GetName().Version).Distinct().ToList();
            if (versions.Count > 1)
            {
                Console.WriteLine($"WARNING: {g.Key} loaded multiple versions: {string.Join(", ", versions)}");
                foreach (var asm in g)
                {
                    WriteAsm(asm);
                }
                Console.WriteLine();
            }
        }
    }
}

Keith MacCrimmon

unread,
Nov 26, 2025, 2:22:31 PMNov 26
to Excel-DNA
Govert,

thank you for the reply.

do you know if anyone else had problems with code like this in core 8.0? 
I ran the two tests you suggested and didnt find anything suspicious:

FullName:   System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Location:   C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.22\System.Net.Http.dll
From GAC:   no
LoadCtx:    System.Runtime.Loader.DefaultAssemblyLoadContext

=== BEGIN EXCEL-DNA DEPENDENCY DIAGNOSTICS ===
Microsoft.Extensions.DependencyInjection      10.0.0.0        ExcelDnaAssemblyLoadContext C:\Users\kmaccrimmon\source\repos\DataFluxAddin3\DataFluxAddin2\DataFluxAddin2\bin\Debug\net8.0-windows\Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.0.0        ExcelDnaAssemblyLoadContext C:\Users\kmaccrimmon\source\repos\DataFluxAddin3\DataFluxAddin2\DataFluxAddin2\bin\Debug\net8.0-windows\Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.Http                     10.0.0.0        ExcelDnaAssemblyLoadContext C:\Users\kmaccrimmon\source\repos\DataFluxAddin3\DataFluxAddin2\DataFluxAddin2\bin\Debug\net8.0-windows\Microsoft.Extensions.Http.dll
System.Net.Http                               8.0.0.0         DefaultAssemblyLoadContext C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.22\System.Net.Http.dll

=== VERSION GROUPS ===

=== END EXCEL-DNA DEPENDENCY DIAGNOSTICS ===


Notice that it didnt find any instances of multiple assembly versions.

Please let me know if you have any other ideas.

thanks

Keith

Keith MacCrimmon

unread,
Nov 26, 2025, 2:30:41 PMNov 26
to Excel-DNA
Suki,

thank you for the reply.

I tried this solution and it didnt work for me. I added version 10 of system.diagnostics.diagostic source since I add latest microsoft.extension.http.
Running the code failed with a failure to load version 10.  Am I missing something?

Keith

Reply all
Reply to author
Forward
0 new messages