Skip to content

Cannot access a disposed object: IServiceProvider when outputting to json #4263

Open
@RoelofSpijker

Description

@RoelofSpijker

Version

4.104.0 (is the version in the path where func.exe is located)
Azure Functions Core Tools
Core Tools Version: 4.0.6821 Commit hash: N/A +c09a2033faa7ecf51b3773308283af0ca9a99f83 (64-bit)
Function Runtime Version: 4.1036.1.23224

Description

When running func.exe host start --dotnet-isolated-debug --enable-json-output --json-output-file c:\somePath\some-file-json.pid it fails with the following error (with CLI_DEBUG=1):

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Azure.Functions.Cli.Actions.HostActions.StartHostAction.RunAsync() in D:\a\_work\1\s\src\Azure.Functions.Cli\Actions\HostActions\StartHostAction.cs:line 437
   at Azure.Functions.Cli.ConsoleApp.RunAsync[T](String[] args, IContainer container) in D:\a\_work\1\s\src\Azure.Functions.Cli\ConsoleApp.cs:line 63

When the file specified exists, it works without issues. It is only when this file does not yet exist that this error occurs.
When not running in debug, so with --dotnet-isolated instead, this works without issues even if the file does not exist.

This is problematic, as the IDE I use (Rider) uses this flag to obtain the PID of the function host worker process, in order to attach the debugger. From what I can tell, the filename is generated semi-randomly by Rider, so I also don't have a workaround of ensuring this file already exists.

Steps to reproduce

  • Have an isolated worker azure function project.
  • Run func.exe host start --dotnet-isolated-debug --enable-json-output --json-output-file c:\somePath\some-file-json.pid when that output file does not exist

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions