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

C++/CLI __declspec(appdomain) static variables cause a C++/CLI binary to fail to load. #110365

Closed
davidwrighton opened this issue Dec 3, 2024 · 1 comment · Fixed by #110367
Closed
Labels
area-AssemblyLoader-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@davidwrighton
Copy link
Member

Description

If a C++/CLI dll has a global variable that is marked with __declspec(appdomain) the binary will fail to load. It will produce an error like the following:

System.IO.FileLoadException: Assembly is still being loaded. (0x80131016 (MSEE_E_ASSEMBLYLOADINPROGRESS))
   at System.Reflection.RuntimeAssembly.InternalLoad(NativeAssemblyNameParts* pAssemblyNameParts, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Reflection.Assembly.Load(String assemblyString)
   at NativeCallingManaged.NativeCallingManaged.TestEntryPoint() in runtime\src\tests\Interop\IJW\NativeCallingManaged\NativeCallingManaged.cs:line 25
   at __GeneratedMainWrapper.Main() in runtime\artifacts\tests\coreclr\obj\windows.x64.Debug\Managed\Interop\IJW\NativeCallingManaged\NativeCallingManaged\XUnitWrapperGenerator\XUnitWrapperGenerator.XUnitWrapperGenerator\SimpleRunner.g.cs:line 7

Reproduction Steps

The bug report was provided privately to the CoreCLR team, and a repro will be provided as part of the fix.

Expected behavior

Assembly should be loadable.

Actual behavior

System.IO.FileLoadException: Assembly is still being loaded. (0x80131016 (MSEE_E_ASSEMBLYLOADINPROGRESS))

Regression?

This is a regression in .NET 9 from .NET 8 related to the work to rebuild how static variables are handled.

Known Workarounds

Remove __declspec(appdomain) from the definition of the global variable. On .NET 9 this has very little semantic effect (it can change initialization order relative to other global variables), causes a minor slowdown when using the variable, and triggers this bug.

Configuration

This only reproduces for C++/CLI binaries as they have a unique startup path which causes the <module> type to be loaded before it would normally be permitted.

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 3, 2024
Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

davidwrighton added a commit to davidwrighton/runtime that referenced this issue Dec 3, 2024
…bly in use. This avoids possible recursive loading issues found in C++/CLI codebases. Repurpose the NativeCallingManaged test to subsume this particular regression test case.

Fix dotnet#110365
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Dec 3, 2024
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 10.0.0 milestone Dec 3, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Dec 6, 2024
github-actions bot pushed a commit that referenced this issue Dec 6, 2024
…bly in use. This avoids possible recursive loading issues found in C++/CLI codebases. Repurpose the NativeCallingManaged test to subsume this particular regression test case.

Fix #110365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-AssemblyLoader-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants