Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crashes unexpectedly without exception on dotnet 9.0 #6

Open
ritos-may opened this issue Dec 6, 2024 · 0 comments
Open

Comments

@ritos-may
Copy link

After upgrading my .net application from 8.0 to 9.0, the application crashes each time the code reaches this line: var app = builder.Build();

After spending hours of debugging it turns out that it's related to CallerInfo Enricher:

public static LoggerConfiguration WithCallerInfo(
    this LoggerEnrichmentConfiguration enrichmentConfiguration,
    bool includeFileInfo,
    string assemblyPrefix,
    string prefix = "",
    string startingAssembly = "",
    int filePathDepth = 0,
    IEnumerable<string> excludedPrefixes = null)
{
    var startingAssemblies = new Stack<Assembly>();
    if (string.IsNullOrWhiteSpace(startingAssembly))
    {
        startingAssemblies.Push(Assembly.GetCallingAssembly());
        startingAssemblies.Push(Assembly.GetEntryAssembly());
    }
    else
    {
        startingAssemblies.Push(Assembly.Load(startingAssembly));
    }

    var referencedAssemblies = GetAssemblies(startingAssemblies,
        asm => asm.Name?.StartsWith(assemblyPrefix, StringComparison.OrdinalIgnoreCase) ?? false,
        asm => excludedPrefixes?.Any(excluded => asm?.Name?.StartsWith(excluded, StringComparison.OrdinalIgnoreCase) ?? false) ?? false);
    return enrichmentConfiguration.WithCallerInfo(includeFileInfo, referencedAssemblies, prefix, filePathDepth);
}

The application crashes, when it reaches this line on the WithCallerInfo method: Assembly.GetCallingAssembly()

I tried to debug it and ran this method on the Watch window on Visual Studio and got this error:

The target process exited with code -1073740791 (0xC0000409) while evaluating the function 'System.Reflection.Assembly.GetCallingAssembly'.

It seems that there is an issue regarding GetCallingAssembly on dotnet 9.0

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

No branches or pull requests

1 participant