JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.02k stars 420 forks source link

Issue with Nuget Package in Azure Functions project #1363

Open yuryshev opened 2 months ago

yuryshev commented 2 months ago

Hello @JKorf ,

There is an issue with NuGet package version 9.7.0 and higher in Azure Functions projects. It generates the following error messages:

[2024-04-06T16:39:12.427Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[2024-04-06T16:39:12.462Z] The 'Function1' function is in error: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

To reproduce this, create a default Azure Functions project and add the latest version of Binance.Net, then run the application.

The previous versions work well.

Thank you

JKorf commented 2 months ago

Hi, what target framework are you using? Seems to work for me with a dotnet6.0 isolated function

yuryshev commented 2 months ago

Hmm... This is strange, first I tested on .net 6 and then switched to .net8 and there was still an error. I'll try to give more context.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
      <PackageReference Include="Binance.Net" Version="9.8.1" />
      <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.3.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
public static class Function1
{
    [FunctionName("Function1")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
        ILogger log)
    {
        return new OkResult();
    }
}
JKorf commented 2 months ago

So I checked this some more, seems it's only an issue when using non-isolated process. For dotnet-isolated runtime it works correctly. I would suggest switching to dotnet-isolated if possible as this is also the recommended runtime from MS.

Steffx115 commented 3 weeks ago

For me this happened when i had mixed isolated/inproc usage in my code