Azure / Azure/azure-functions-host
Dependency Injection : ValueFactory attempted to access the Value property of this instance.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
This is a follow up on issue https://github.com/Azure/azure-functions-host/issues/5074
In FunctionStartup (FYI same error when using IWebJobsStartup) I have this:
```csharp
builder.Services.AddHttpClient("global",...... //shortened
builder.Services.AddSingleton();
builder.Services.AddSingleton();
```
```csharp
public class SharepointServiceProvider
{
private readonly ServiceDependencyInjectionProxy Proxy;
private readonly HttpClient HttpClient;
public SharepointServiceProvider(ServiceDependencyInjectionProxy proxy)
{
this.Proxy = proxy ?? throw new ArgumentNullException(nameof(proxy));
HttpClient = Proxy.HttpClientFactory.CreateClient("global");
HttpClient.Timeout = Timeout.InfiniteTimeSpan;
}
}
```
and ServiceDependencyInjectionProxy is getting IHttpClientFactory injected in its constructor, and exposed a HttpClientFactory property to access the injected factory
I get the following thrown at me
```csharp
An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'ValueFactory attempted to access the Value property of this instance.'
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateHandler(String name)
at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateClient(String name)
at be.signdisplay.SharepointServiceProvider..ctor(ServiceDependencyInjectionProxy proxy)
```
when SharepointServiceProvider is getting injected in any other constructor
Contributor guide
Assessment
This issue has not been assessed yet.