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
Compiling Azure Functions with NuGet package dependencies fails #154
Comments
Could you please expand a little more information to reproduce your issue? Base class for what for the commands or for the command handlers? Your project that you publish in NuGet refers Microsoft. Extensions.Dependency Injection.Abstractions or FunctionMonkey nuget packages? |
Typically each Azure Function would implement Our particular setup is using MediatR along with several service registrations that are common to all the Azure Function projects. Because we have multiple Azure Functions, we created a base class that abstracts the common setup like logging, validation, and pipeline creation. It looks like this for any given Azure Function:
Originally both classes were part of the same solution. Since then, we've moved our core libraries to a NuGet feed. The ApiBootstrap (and several project dependencies and service implementations) are now referenced in the project via NuGet instead of a direct project reference. After that one change, the FunctionMoneky compiler isn't able to compile the functions. We've traced it down to any external class or interface that's now referenced in a NuGet package. Keep in mind, these classes haven't changed at all; only the way they're referenced in each project has changed. It appears that the FunctionMonkey target can't compile the code when it tries to find implementations. For example, we have a class called
Note that the error says it can't find Blueprint.Forms.Api.IDatabaseInitializer. When we remove the code that registers the the instance, we get a slightly different, but still failing error:
In this case, the FunctionMonkey compiler still cannot find the type that the FunctionAppConfiguration inherits from. Again, when all the code is in a single project it works fine. But moving base classes to a NuGet package is enough to cause FunctionMonkey to fail during compilation. |
Yes, one of the NuGet packages references FunctionMonkey as a NuGet project reference |
I pulled down the FunctionMonkey source and ran against an empty project with the same error. That's good news; it's not hard to reproduce. The code fails in FunctionMonkey.Compiler when loading assemblies even though the assembly is there in the correct directory Specifically, the failure is thrown by
|
Uncovering more as I dig deeper. I found a couple odd behaviors I can't yet explain. First, the assembly resolving fails outright to load the Microsoft.Extensions.DependencyInjection.Abstractions DLL in the Resolving lambda. I modified it as follows to allow the assembly to load, and so far it seems to work:
That modification at least resolves and successfully loads the assembly, but it's not sufficient to get the compilation to work. What follows after assembly and type loading (i.e. after the call to FindFunctionAppHost) is something I can't yet explain. I'm not at all new to reflection, but this is something I've not encountered before. Around line 90 in the compiler, the compiler attempts to invoke Now, when the Build is invoked, reflection cannot find the method and throws an exception when attempting to call it. The strange thing is that the method is there. To test further, I added a method called "BuildTest" to my Azure function, and then instead of calling The temporary function looks like this:
Here's where I'm stumped - I set a breakpoint on the I will keep digging, but this one is a first for me. It may have to do with .Net Core and package management in some way. All the projects are .Net Core 3.1; perhaps there's something about that which prevents the method invocation. |
Not sure if this is related, but I had a similar issue when upgrading to Microsoft.NET.Sdk.Functions 3.0.6 with various nuget packages failing with "Unexpected error: Could not load file or assembly" errors. I was able to resolve them by adding |
I tested my project with a version of Microsoft.NET.Sdk.Functions greater than 3.0.3 and started getting the same error "Could not load file or assembly"... @TylerBrinks could you please describe which version of Microsoft.NET.Sdk.Functions you are using? |
I'm using 3.0.6 but I'll try the 3.0.6 release. |
I made that change and something changed. I'm able to access my base class' methods now from the derived class. I still can't invoke them from the FunctionMonkey compiler, but it's a step closer. |
I double checked my original solution (as opposed to my scratch project in the FunctionMonkey solution) and I was already on 3.0.6 and happened to have the One fact that may have some relevance, when the assemblies are loaded mine are all .NETCoreApp,v=3.1 where the Microsoft dependency injection assembly is .NETStandard,v2.0 |
@TylerBrinks Try to downgrade Microsoft.NET.Sdk.Functions to 3.0.3 version. |
Just did that in both my actual project and a scratch project in the FunctionMonkey code with same error. I'm not sure if much will work if the compiler can't get past the inability to load the Microsoft.Extensions.DependencyInjection.Abstractions library. |
We are using FunctionMonkey built with Azure Pipelines in production. I believe I can remember these problems. The root cause was that parts of the required libraries are loaded from the SDK and in an Azure Pipeline build this works somehow different from a local build.
Our full YAML pipeline file as reference (some things overwritten with xxxxxxxxxxxxxxxx): pool:
variables: steps:
Hope this helps somehow and good luck, |
I have a solution with multiple Azure Function HTTP APIs. They were previously using a shared base class in the same project and were able to build without issue. Now, the shared base class has been moved to a NuGet package. Using the base class from the installed NuGet package (even with symbols) fails to compile with the following message:
The text was updated successfully, but these errors were encountered: