Skip to content

Commit 43d1838

Browse files
Fix C++/CLI applications which use __declspec(appdomain) (#110367)
* Do not eagerly allocate static variable space while loading the assembly 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 * Fix testcase
1 parent fdb68dd commit 43d1838

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/coreclr/vm/methodtable.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -4316,7 +4316,10 @@ void MethodTable::DoFullyLoad(Generics::RecursionGraph * const pVisited, const
43164316
ClassLoader::ValidateMethodsWithCovariantReturnTypes(this);
43174317
}
43184318

4319-
if ((level == CLASS_LOADED) && CORDisableJITOptimizations(this->GetModule()->GetDebuggerInfoBits()) && !HasInstantiation())
4319+
if ((level == CLASS_LOADED) &&
4320+
CORDisableJITOptimizations(this->GetModule()->GetDebuggerInfoBits()) &&
4321+
!HasInstantiation() &&
4322+
!GetModule()->GetAssembly()->IsLoading()) // Do not do this during the vtable fixup stage of C++/CLI assembly loading. See https://github.com/dotnet/runtime/issues/110365
43204323
{
43214324
if (g_fEEStarted)
43224325
{

src/tests/Interop/IJW/IjwNativeCallingManagedDll/IjwNativeCallingManagedDll.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ extern "C" DLL_EXPORT int __cdecl NativeEntryPoint()
1717
}
1818

1919
#pragma managed
20+
21+
// Needed to provide a regression case for https://github.com/dotnet/runtime/issues/110365
22+
[assembly:System::Diagnostics::DebuggableAttribute(true, true)];
23+
[module:System::Diagnostics::DebuggableAttribute(true, true)];
24+
25+
public value struct ValueToReturnStorage
26+
{
27+
int valueToReturn;
28+
bool valueSet;
29+
};
30+
31+
// store the value to return in an appdomain local static variable to allow this test to be a regression test for https://github.com/dotnet/runtime/issues/110365
32+
static __declspec(appdomain) ValueToReturnStorage s_valueToReturnStorage;
33+
2034
public ref class TestClass
2135
{
22-
private:
23-
static int s_valueToReturn = 100;
2436
public:
2537
int ManagedEntryPoint()
2638
{
@@ -29,12 +41,16 @@ public ref class TestClass
2941

3042
static void ChangeReturnedValue(int i)
3143
{
32-
s_valueToReturn = i;
44+
s_valueToReturnStorage.valueToReturn = i;
45+
s_valueToReturnStorage.valueSet = true;
3346
}
3447

3548
static int GetReturnValue()
3649
{
37-
return s_valueToReturn;
50+
if (s_valueToReturnStorage.valueSet)
51+
return s_valueToReturnStorage.valueToReturn;
52+
else
53+
return 100;
3854
}
3955
};
4056

0 commit comments

Comments
 (0)