-
Notifications
You must be signed in to change notification settings - Fork 42
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
FunctionsStartup is not being called, causing function dependency resolution to fail. #5
Comments
#8 |
Thank you very much for your time, your solution did the trick and we got it working! |
@worleywa7 Just curious, have you tried publishing a function with DI to azure? Mine works locally, but crashes instantly in the cloud with a DependencyIncetion error.. |
Okay, let the randomness begin.. 1.0.27 and 1.0.28 doesnt work in azure for dependency resolution, BUT 1.026 does. And when downgradig to 1.0.26 it suddenly works locally aswell! |
Looks like we're getting the same issue as well; wasn't readily apparent until now. We're going to downgrade as well; see what we come up with. |
I take it back, not trying 1.0.28. |
Looks like we're back to the drawing board: 'The function runtime is unable to start. Functions: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'. Timestamp: 2019-05-16T15:13:38.648Z' |
So we did what you said at first, and it worked; that's why I closed the ticket.. I saw exactly what I wanted to see in my project. However, since then, I added nugets from two .NET Standard libraries, injected a dependency from one of those libraries, and have created functions that rely on this DIs. |
I tried the scopes sample - no other references. As provided with 1.0.26 it failed locally and on Azure. With Dependencies updated (1.0.28) it runs locally but when deployed to Azure I get : Is there a way to do some logging in the startup function so we can see if it being run when deployed? |
So what it ended up being was, for me at least, there was a dependency that I forgot to inject. There was a single "Object cannot be null" line in a log on the azure portal that seemed to be the issue. We're back to running our functions on 1.0.28 in the Cloud. |
The only way to get DI to work for me when deployed to Azure is using 1.0.26. 1.0.26, 1.0.27, 1.0.28 all works fine local |
|
Finally got this working. According to [(https://github.com/Azure/azure-functions-host/issues/3386#issuecomment-497492442)] the suggestion to add a reference to ExtensionsMetadataGenerator is bad. Remove this reference if you have it. |
1.0.29 not working, same issue as described in #14 (closed due to author moving on to Aws Lambda...) Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type '...' while attempting to activate '...' |
That's totally fine for me on development and production when I create new project, but same error when i try to add DI in existing project/solution. So why this error in existing project/solution, that's discussed here dotnet/extensions#1718 Here's my working project configurations:
Notice i'm using, function v2, netcoreapp3.0, Sdk.Function 1.0.29 and Function.Extension 1.0.0. Sample project here https://github.com/itorian/AzureFunctionDISample, if you running this sample please update AzureWebJobsStorage in local.settings.json or use emulator |
Same issue for me
|
Same here... Happening when I reference
|
I had the same issue today. I removed some Nuget packages and added a namespace declaration to my Startup.cs and the problem was fixed. Using SDK 1.0.29. Not sure if this matters, but check if your Startup class has a namespace. |
At this moment the solution is only to downgrade to .NET Core 2.2 |
I'm on the same boat, these combinations of NuGet versions are not working: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AzureFunctionsVersion>v3-preview</AzureFunctionsVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.0-preview2" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project> Error is |
is out. Still
EDIT: I got rid of the exception above by downgrading all Microsoft.Extensions.* to 3.0.1 |
Is the runtime version still on preview? https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions |
Tested locally with v3 instead of v3-preview with no success (No function runtime available) |
And this error still persist: |
I had issues when using preview without having visual studio 16.4 preview installed & preview environment variable enabled. Maybe try installing visual studio 16.4 with the official release nuget? old ref: https://dev.to/azure/develop-azure-functions-using-net-core-3-0-gcm Here is my sample csproj that I had it working with locally during preview. <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AzureFunctionsVersion>v3-preview</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.0-preview1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project> |
This seems like it could also be related to Azure/azure-functions-host#5401. |
Closing this issue as there is a mix of different problems tracked here, and they should be resolved with the release of Azure Functions 3.0 (many of the issues here are related to running on Azure Functions 2.0 while targeting .NET Core 3.0). If you continue to have issues, please open a new issue with details and we'll investigate them. Thank you! |
We downloaded the sample project, put a break point on builder.Services.AddScoped<IGreeter, SampleGreeter>(); expecting it to be called when the runtime started and discovered functions. Unfortunately it did no, so we attempted to invoke the function directly to see if the runtime would call the FunctionStartup class upon first function invocation. Unfortunately it did not and both times resulted in:
Executed 'SampleFunction' (Failed, Id=eeaabc43-d8a6-4815-9fe2-0834f7d4c47b)
[5/8/2019 9:58:22 PM] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.IGreeter' while attempting to activate 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.SampleFunction'.
Is there something we are missing? It does not appear that the FunctionsStartup method is actually being called by the runtime.
The text was updated successfully, but these errors were encountered: