Jericho / ZoomNet

.NET client library for the Zoom.us REST API v2
MIT License
68 stars 48 forks source link

`could not load file or assembly` when using ZoomNet in Azure function #304

Closed joshrogers-pg closed 1 year ago

joshrogers-pg commented 1 year ago

We are attempting to use your library in an Azure Function (v4) which is .Net 6. The ZoomNet library claims to support .Net 6 but there is a dependency on Microsoft.Extensions.Logging 7.0.0 and System.Text.Json 7.0.3.

Reproduction steps:

  1. Create an Azure Functions (v4) application with at least 1 function
  2. Add a reference to ZoomNet 0.64
  3. Attempt to run the application
  4. Observe the runtime failure: The 'TestTrigger' function is in error: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

I was able to produce a dll using the source with using v6 versions of System.Text.Json and Microsoft.Extensions.Logging and the error went away and application was usable.

Jericho commented 1 year ago

I have a pretty good idea what the problem might be but before I get into that, allow me to take issue with something you said:

The ZoomNet library claims to support .Net 6 but there is a dependency on Microsoft.Extensions.Logging 7.0.0 and System.Text.Json 7.0.3

ZoomNet doesn't just "claim" to support .NET 6, as you said. It DOES in fact support it. I understand that you are experiencing a problem and I also realize that your app is targeting .Net 6 but that's not enough evidence to conclude that ZoomNet doesn't support .Net 6.

It is also true that we reference the two Nuget packages you mention but I fail to understand why that would be an indication that we don't support .NET 6. Are you implying that referencing these two packages breaks compatibility with .NET 6? I would love to understand how you reached that conclusion. If you look at the frameworks supported by the Microsoft.Extension.Logging, you will see that it supports .NET 6. So, again, I don't see how you came to the conclusion that referencing this package somehow means that ZoomNet is not compatible with .NET 6.

Also, don't be fooled by the versioning of the two dependencies you mentioned. The fact that their version number starts with 7 doesn't mean they are intended to be used on .NET 7 exclusively and it certainly doesn't mean that they are not compatible with .NET 6 and/or that libraries referencing them become incompatible with .NET 6.

Now that I have made it clear the ZoomNet supports .NET 6 and that the two NuGet packages you mentioned also support .NET 6, and that I don't think the evidence you have provided so far is sufficient to conclude that ZoomNet doesn't support .NET 6, let's try to dig deeper and figure out why you are getting a Could not load file or assembly exception.

Would it surprise you if I told you you are not the first one to report this problem? In fact, other developers have experienced this problem in Azure function too: here, here, here and here. These are just a few examples and a quick Google search will help you find more examples of Could not load file or assembly... in Azure function. The thing to note about all these examples is that they have nothing to do with ZoomNet. This is a strong indication that the issue resides with the Azure function environment rather than with ZoomNet, wouldn't you agree?

I'm no Azure expect so take what I say with a grain of salt but here's my understanding of the problem:

Have you tried using out-of-process (I think it's actually called "isolated" in Azure lingo, not 100% sure) rather than in-process? This would give you the flexibility of referencing any nuget package without conflicting with the packages used by the Azure function environment.

Another suggestion would be to upgrade to .NET 7. This article leads me to believe Azure function supports .NET 7. Hopefully, the .NET 7 Azure function environment references updated version of the nuget packages which does not conflict with ZoomNet. Please note that I make this suggestion not because of the .NET version, but rather because I suspect that a more recent Azure function environment references more recent version of the aforementioned NuGet packages.

However, I am pretty confident that you will find yourself in the exact same situation when Microsoft.Extension.Abstration version 8 is released and ZoomNet updates its references to this latest version. And again with each subsequent release of the NuGet package until the Azure function is improved to work around the fact that .NET projects can reference more recent versions of the packages it also references.

Let me say that I realize ZoomNet is what exposed this problem to you and therefore it "feels" like ZoomNet is the source of the problem, but I don't think that's the case. The root of the problem, based on my understanding of the situation, is that there is a NuGet package version mismatch between the Azure environment and your project. In your case, this mismatch is caused by ZoomNet, I'll give you that, but you would have the exact same problem if your project directly referenced a NuGet package that caused the mismatch. In fact, you can probably validate what I just said by attempting to publish a .NET project to Azure function with a direct reference to Microsoft.Extension.Logging.Abstraction version 7 (make sure your project does not reference ZoomNet) and you should experience the same could not load ... error.

Also, thank you for the PR which downgrades the NuGet reference to an older version, but I'm afraid that it does not solve the underlying problem. The root of this issue is that you are trying to load your app in the same process as the Azure environment which ultimately leads to NuGet package version mismatch because Azure is also loading a different version of the same package. I think the best solution which will work with Microsoft.Extension.Abstration version 7, upcoming version 8 and any other future version, is simply to use the "isolated" process in Azure. This gives you total flexibility to load any NuGet package either directly or indirectly without any fear of version mismatch with the Azure environment.

Let me know if this helps.

joshrogers-pg commented 1 year ago

My apologies, as I did not mean to insult or disparage you or the product. My phrasing was a poor choice, I guess, but I was just trying to convey the contrast contrast of the expectation in thethat .Net 6 was supported and the results that I was experiencing, that it was not working within a .Net 6 application. When making those version changes it began working.

I appreciate the thought and thoroughness that you still put into the answer and I am sure you're correct. Thank you.

Jericho commented 1 year ago

No need to apologize. It’s all good. I reacted strongly because I want to make it clear that ZoomNet indeed supports the .net frameworks that we say we support.

I would be curious to continue the discussion and hear if any of my suggestions helped. Also, I’m not aware of any way the I can totally prevent version mismatch in Azure function environment but I want to keep an open mind and listen to suggestions.