Skip to content

[mono] AppContext.BaseDirectory is empty in some cases #31800

Closed
mono/mono
#18720

Description

@EgorBo

When I run runtest.py (see make run-tests-coreclr-all) with Mono Runtime bits inside the Core_Root it crashes with

    Unhandled Exception:
    System.TypeInitializationException: The type initializer for 'Internal.Microsoft.Extensions.DependencyModel.CompilationLibrary' threw an exception.
     ---> System.TypeInitializationException: The type initializer for 'Internal.Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment' threw an exception.
     ---> System.ArgumentException: The path is empty. (Parameter 'path')
       at System.IO.Path.GetFullPath(String path)
       at Internal.Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.GetApplicationBasePath()
       at Internal.Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment..cctor()
       --- End of inner exception stack trace ---
       at Internal.Microsoft.Extensions.DependencyModel.Resolution.AppBaseCompilationAssemblyResolver..ctor(IFileSystem fileSystem)
       at Internal.Microsoft.Extensions.DependencyModel.Resolution.AppBaseCompilationAssemblyResolver..ctor()
       at Internal.Microsoft.Extensions.DependencyModel.CompilationLibrary..cctor()

It looks like GetBaseDirectoryCore returns empty string on first usage (and then a correct string after).

cc @CoffeeFlux

Activity

  1. added
    untriaged
    on Feb 5, 2020
  2. added and removed
    untriaged
    on Feb 5, 2020
  3. self-assigned this
    on Feb 5, 2020
  4. CoffeeFlux commented on Feb 5, 2020

    @CoffeeFlux
    Contributor

    In some cases, the domain's entry_assembly appears to be null, including during the first call to GetEntryAssembly().

  5. CoffeeFlux commented on Feb 5, 2020

    @CoffeeFlux
    Contributor

    The problem appears to be that the assembly preload hook is triggered early, before prepare_thread_to_exec_main is run. On netcore, the preload hook includes a call to managed to locate the BaseDirectory, and the icall returns null because prepare_thread_to_exec_main is where the entry_assembly is actually set.

  6. added a commit that references this issue on Feb 7, 2020
    1635c21
  7. ghost locked as resolved and limited conversation to collaborators on Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions