Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException System.Net.Http.SocketsHttpHandler.get_MeterFactory() with 2.1.0-beta2 on .NET 8.0 #297

Open
kaspermarstal opened this issue Nov 22, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@kaspermarstal
Copy link

Service

OpenAI

Describe the bug

The explicit dependency on System.Diagnostic.DiagnosticSource results in System.Diagnostic.DiagnosticSource.dll being copied to build directory. When the program is started, two such dlls are loaded on my machine, one from build directory and one from system directory, and I get a MissingMethodException:

'EXCEL.EXE' (CoreCLR: clr_libhost): Loaded 'C:\Users\kaspe\source\repos\cellm\src\Cellm\bin\Debug\net8.0-windows\System.Diagnostics.DiagnosticSource.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'EXCEL.EXE' (CoreCLR: clr_libhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.0\System.Diagnostics.DiagnosticSource.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
ExcelDna.Integration Error: 1 : DnaLibrary AutoOpen Invoke Error : MissingMethodException - Method not found: 'System.Diagnostics.Metrics.IMeterFactory System.Net.Http.SocketsHttpHandler.get_MeterFactory()'.

A workaround is to explicitly exclude this dependency from being copied to the build directory in my own csproj file:

    <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" >
      <ExcludeAssets>runtime</ExcludeAssets>
    </PackageReference>

This results in only the C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.0\System.Diagnostics.DiagnosticSource.dll being loaded and the program works fine.

Steps to reproduce

  1. Create a project
  2. Set net8.0-windows
  3. Add will depends on OpenAI 2.1.0-beta2
  4. Build and run

Code snippets

No response

OS

win

.NET version

8.0

Library version

2.1.0-beta2

@kaspermarstal kaspermarstal added the bug Something isn't working label Nov 22, 2024
@kbiasci-centrix
Copy link

kbiasci-centrix commented Jan 13, 2025

I have the same issue with .Net 8 when trying to run
HttpClient CreateClient(this IHttpClientFactory factory);
Result is:
Method not found: 'System.Diagnostics.Metrics.IMeterFactory System.Net.Http.HttpClientHandler.get_MeterFactory()'
But it's NOT only related to openAI, it's linked to .Net

@edmd
Copy link

edmd commented Jan 13, 2025

@kbiasci-centrix i've been experiencing this same issue with this exact method in a .net 8 lambda. How have you worked around this?

@kbiasci-centrix
Copy link

kbiasci-centrix commented Jan 13, 2025

@kbiasci-centrix i've been experiencing this same issue with this exact method in a .net 8 lambda. How have you worked around this?

It is also related to a Lambda function project who suddenly started to fail locally on my side.
I tried to create a new HTTPClient via:

var client = httpClientFactory.CreateClient();

and the error I had was:

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

To fix it, I used the workaround suggested above, I have modified the project file and added the "System.Diagnostics.DiagnosticSource" nuget package:

<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" >
      <ExcludeAssets>runtime</ExcludeAssets>
    </PackageReference>

@maanlegaspi
Copy link

I had the same issue with .net 8 lambda, my workaround is to downgrade System.Diagnostics.DiagnosticSource to version 8.0.1 for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants