CloudinaryDotNet icon indicating copy to clipboard operation
CloudinaryDotNet copied to clipboard

Version 1.15.1 and 1.15.2 - Could not load file or assembly Microsoft.Extensions.Options

Open coder-candace opened this issue 4 years ago • 5 comments

Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

We are using the SDK in a .NET Core 3.1 Azure Function project. On startup we get the following error message.

[2021-10-05T19:14:11.699Z] A host error has occurred during startup operation '929d6984-66be-444d-b0b2-d4645ccc7549'.
[2021-10-05T19:14:11.701Z] Function-ZipWhipEngine: Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Value cannot be null. (Parameter 'provider')

In order to resolve the error we have to downgrade to version 1.14.0. …

Issue Type (Can be multiple)

  • [X] Build - Cannot install or import the SDK
  • [ ] Performance - Performance issues
  • [ ] Behaviour - Functions are not working as expected (such as generate URL)
  • [ ] Documentation - Inconsistency between the docs and behaviour
  • [ ] Other (Specify)

Steps to reproduce

Simply upgrade the NuGet package and try to run the project. Error will occur during startup.

Error screenshots or Stack Trace (if applicable)

image

OS and Version

  • [ ] Linux
  • [X] Windows
  • [ ] macOS
  • [ ] MultiPlatform

Versions and Libraries (fill in the version numbers)

  • Cloudinary .NET SDK version - 1.15.1 and 1.15.2
  • .NET Core - 3.1

coder-candace avatar Oct 05 '21 19:10 coder-candace

Hi @coder-candace Could you please let me know what is the target framework set for your library Function-ZipWhipEngine (i.e. it should also be .Net Core 3.1)? The error thrown is from Microsoft.Extensions.Options which is a dependency for Microsoft.Extensions.WebEncoders (target framework .Net Core 3.1). In case, may I request a sample library that throws this exception so I could verify it further in my dev environment? Thanks.

epasos573 avatar Oct 08 '21 04:10 epasos573

Hi @epasos573 yes the target framework is .NET Core 3.1.

I was able to further narrow down where the problem is occurring. It's happening on this line. [assembly: FunctionsStartup(typeof(Function_ZipWhipEngine.Startup))]

If you remove that line, error goes away and project fires up as expected. Add it back and error returns. Problem is if we just remove this line then our Configure() override won't run and we can't set up required application settings.

Here is a sample project demonstrating the issue ZipWhipEngine-Sample3.zip

coder-candace avatar Oct 12 '21 21:10 coder-candace

Hi @coder-candace Thanks for the sample code and after verifying the issue, I could see that the Microsoft.Extensions.Options is having a conflict with the Microsoft.Extensions.WebEncoders on application load.

To replicate the issue, I have updated the sample code you have provided. I uninstalled CloudinaryDotNet package and installed the Microsoft.Extensions.WebEncoders package into ZipWhipEngine project . And launching the application throws the issue: Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. Value cannot be null. (Parameter 'provider').

Testing the case further, I have used the Environment.CurrentDirectory instead in order to set the application base path.

    var appDirectory = Environment.CurrentDirectory;
    configurationBuilder.SetBasePath(appDirectory)
             .AddJsonFile("appSettings.json", false, true)
             .AddJsonFile("local.settings.json", true, true)
             .AddEnvironmentVariables();

See attached updated project ZipWhipEngine_Modified.zip :

epasos573 avatar Oct 13 '21 10:10 epasos573

I also have the same issue - basic install into a .NET Core 3.1 DLL with only these dependencies.

  <ItemGroup>
	  <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.17" />
	  <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.17" />
	  <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.17" />
  </ItemGroup>

JT-Bruch avatar Dec 06 '21 17:12 JT-Bruch

@JT-Bruch The CloudinaryDotNet SDK is compatible with .Net Core 3.1, while the error reported above is linked to the other Microsoft packages used in the solution that are not yet compatible with .Net Core 3.1. And the proposed solution is to use other libraries that is fully functional with the version of .Net Framework/Core being used.

As for your case, reviewing the dependencies requirements for Microsoft.Extensions.DependencyInjection.Abstractions (see Nuget link), it is only compatible with .NETStandard 2.0.

Please take a look and see if that helps.

epasos573 avatar Dec 07 '21 05:12 epasos573