azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Cannot Access a Disposed Object: IServiceProvider

Open campelo opened this issue 2 years ago • 2 comments

I've the same problem of #2471

I'm using isolated-function and initially this local.settings.config works. But when we continue relaunching the application for debugging we receive the error Cannot Access a Disposed Object: IServiceProvider without reason.

"Host": {
    "LocalHttpPort": 7071,
    "CORS": "*",
    "CORSCredentials": true
  }

But this config always works without problems.

"Host": {
    "LocalHttpPort": 7071,
    "CORS": "*",
    "CORSCredentials": false
  }

Here's some dependency versions I'm using:

<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>

something else...

<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.9.0" />

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    
something else...

  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*",
    "CORSCredentials": true
  }
}

campelo avatar Apr 26 '23 15:04 campelo

Having the exact same issue, very frustrating as it prevents me from receiving credentials in my API function.

Cannot access a disposed object.
Object name: 'IServiceProvider'.

When CORSCredentials is set to true...making is almost impossible for me to develop against an isolated function API

eswann avatar Aug 21 '24 16:08 eswann

For anyone else hitting this, you need to specify a specific host in the CORS setting to use CORSCredentials. See here for details https://stackoverflow.com/a/77152249

It would be nice if a more legible error message was returned in this case though

Matt343 avatar Sep 12 '24 18:09 Matt343