question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependency Injection in Azure Functions results "Unable to resolve service for type..." error

See original GitHub issue

Hi,

I had a azure function running when it suddenly didn’t and returned the error: Unable to resolve service for type... Which is surprising for I have other azure functions with DI running without issue.

All functions work fine in local system.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brettsamcommented, Jan 30, 2020

@ThapaMahesh – can you check that this host file is being deployed to Azure? It doesn’t appear that it is, and you’re running into a bug that was introduced recently when a host.json file is missing. It causes us to incorrectly inject the usage of extensions bundles, which means we’re not calling your startup class.

We see this in your logs, which means that there was no host.json, so we generated one for you:

Host configuration file read:
{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

If you make sure to deploy the default host.json from above, it should get back to working again.

//cc @soninaren

0reactions
ThapaMaheshcommented, Jan 30, 2020

@siji147 the host file contains { "version": "2.0" }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection unable to resolve service for type in . ...
In the solution that defines our function app (.NET Core 2.2) I've made sure the right NuGet packages are installed: Microsoft.Azure.Functions.
Read more >
Dependency Injection issue: Unable to resolve service for ...
I just deployed the function to Azure, and it is working. It's only locally I'm getting this error.
Read more >
Implement Dependency Injection in Azure Functions for ...
Solution was to use the interface in the constructor, not the instance class. Apparently, I am not alone: https://stackoverflow.com/questions/ ...
Read more >
Azure Function DI Failure Unable to resolve service for ...
DependencyInjection : Unable to resolve service for type 'Microsoft.Azure.WebJobs.Script.IEnvironment' while attempting to activate 'Microsoft.
Read more >
Use dependency injection in .NET Azure Functions
Learn how to use dependency injection for registering and using services in .NET functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found