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
Dependency Injection in Azure Functions causing Object reference error #1440
Comments
I hate Azure Functions so much. I've never once seen a project say, "Worked the first time." I don't know what to tell you, other than I have lost my desire to continue troubleshooting Azure Functions. I dealt with a bunch of bugs in RazorLight, too - that had nothing to do with RazorLight, but rather how poorly Azure Functions supports modular coding. I gave them feedback awhile ago and they downvoted my comments. So I pretty much peaced out after that interaction. I guess I'd prefer to discuss, how does one integration test Azure Functions? Is it even testable? As in, testable without running func.exe and all its machinary. I don't use Azure - I use AWS and AWS Lambda supports deploying an EXE in a docker container. Seems a lot simpler and more maintainble to me, as you get more control over when your application upgrades anything in its dependency graph. Plus it eliminates one more variable, which is the Azure Functions SDK is a separate SDK from the core .NET SDK. I just don't get it. FluentMigrator doesn't create a FluentMigrator SDK with a bunch of deployment logic tucked away in MSBuild targets. |
The problem you're probably running into is the stupid default behavior of Azure Functions SDK. By default, the SDK optimizes away your dependency tree if there are no symbol references in your project to a referenced dll. So you should probably start by seeing if your deploy directory has the right FluentMigrator dlls. I know, it's crazy. This was one of the feedback items I gave them they downvoted. One workaround is to disable the default behavior. Another is to create an Assembly-level attribute to reference any type in the concrete Runner class. Otherwise, in my opinion, the only way Azure FUnctions gets better is if they get more and more support requests until they realize their product is simply not good enough. Sorry for the rant. |
Hi @jzabroski & @DarrenWainwright, I've just encountered exactly the same problem. Is there any update, or have you ever managed to make it work? |
Describe the bug
Trying to use FluentMigrator in an Azure Functions v3 app, and implementing with Dependency Injection. Database being used against is Postgre.
Experiencing an 'Object reference not set to an instance of an object' when trying to inject IMigrationRunner, or trying to access it in the IServiceProvider.
To Reproduce
Followed the steps on the projects quick start. Snippets of the important code are here:
Startup.cs:
DbMigrations file - attempt 1:
this one will not run at all - IMigrationRunner is null, so DI can't spin it up
Attempt 2:
This one fails trying to grab the required service, same error:
Expected behavior
Expected IMigrationRunner to exist and be able to call
.Up()
Information (please complete the following information):
-- FluentMigrator v3.2.15
-- FluentMigrator.Runner v 3.2.15
-- FluentMigrator.Runner.Postgre v3.2.15 (tried with and without this installed)
-- FluentMigrator.Runner.Core v3.2.15 (tried with and without this installed)
The text was updated successfully, but these errors were encountered: