Skip to content

Fix base directory resolution for custom hosting environments#183

Merged
DevD4v3 merged 1 commit into
masterfrom
patch-1
Jun 7, 2026
Merged

Fix base directory resolution for custom hosting environments#183
DevD4v3 merged 1 commit into
masterfrom
patch-1

Conversation

@DevD4v3

@DevD4v3 DevD4v3 commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

This change introduces a PathResolver utility to centralize base directory resolution.

Previously, DotEnv.Core relied directly on AppContext.BaseDirectory when searching for .env files. While this works in most .NET hosting scenarios, it does not behave reliably under SampSharp/open.mp hosting.

The new implementation falls back to Directory.GetCurrentDirectory() when AppContext.BaseDirectory is unavailable, providing a more resilient path resolution strategy.

Motivation

While migrating a game mode to SampSharp.OpenMp.Entities, .env files could not be located correctly because AppContext.BaseDirectory was not available as expected.

According to SampSharp maintainer Tim Potze:

Due to technical limitations of dotnet it's not possible to set the AppContext.BaseDirectory.

As a result, libraries that assume AppContext.BaseDirectory is always available may fail in custom hosting environments.

Changes

  • Added PathResolver utility class.
  • Centralized base directory resolution logic.
  • Added fallback to Directory.GetCurrentDirectory().
  • Replaced direct usages of AppContext.BaseDirectory with PathResolver.BaseDirectory.

AppContext.BaseDirectory may not be available in all hosting environments.

Introduce PathResolver to provide a consistent base directory resolution strategy by falling back to Directory.GetCurrentDirectory() when AppContext.BaseDirectory is unavailable.
@DevD4v3 DevD4v3 merged commit 24a633b into master Jun 7, 2026
1 check passed
@DevD4v3 DevD4v3 deleted the patch-1 branch June 7, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant