forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unloadable AssemblyLoadContext API and tests (dotnet/corefx#32002)
* Add unloadable AssemblyLoadContext API and tests The change is based on dotnet/corefx#14763, but I had to change many things due to the fact that the project.json files are not used anymore and due to the slighly different semantics of the Unloading event, which now fires when the unloading is about to start and doesn't indicate the unload is almost done as before. Additional changes: * Tests for all remaining unsupported features: * delegate marshalling for types in collectible assemblies * FixedAddressValueTypeAttribute * COM interop * Removed checked in binary System.Runtime.Loader.Test.Assembly.dll, modified the msbuild projects to build it at the build time instead. * Added the new APIs to ApiCompatBaseline Commit migrated from dotnet/corefx@cfb501e
- Loading branch information
Showing
19 changed files
with
724 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
using System.Threading; | ||
|
||
namespace System.Runtime.Loader.Tests | ||
{ | ||
|
||
public partial class AssemblyLoadContextTest | ||
{ | ||
class DelegateMarshallingTest : TestBase | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public void Execute() | ||
{ | ||
// Delegate marshaling for types within collectible assemblies is not supported. | ||
Assert.Throws<NotSupportedException>(() => | ||
{ | ||
MethodInfo methodReference = _testClassTypes[0].GetMethod("TestDelegateMarshalling"); | ||
Assert.NotNull(methodReference); | ||
methodReference.Invoke(null, BindingFlags.DoNotWrapExceptions, Type.DefaultBinder, null, null); | ||
}); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void Unsupported_DelegateMarshalling() | ||
{ | ||
var test = new DelegateMarshallingTest(); | ||
test.CreateContextAndLoadAssembly(); | ||
test.Execute(); | ||
test.UnloadAndClearContext(); | ||
test.CheckContextUnloaded(); | ||
} | ||
|
||
|
||
class COMInteropTest : TestBase | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public void Execute() | ||
{ | ||
// COM Interop is not supported for collectible types. | ||
Assert.Throws<NotSupportedException>(() => | ||
{ | ||
Type contextMenuType = _testClassTypes[0].GetNestedType("COMClass"); | ||
Assert.NotNull(contextMenuType); | ||
Assert.True(contextMenuType.IsCOMObject); | ||
object contextMenu = Activator.CreateInstance(contextMenuType); | ||
Assert.NotNull(contextMenu); | ||
}); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void Unsupported_COMInterop() | ||
{ | ||
var test = new COMInteropTest(); | ||
test.CreateContextAndLoadAssembly(); | ||
test.Execute(); | ||
test.UnloadAndClearContext(); | ||
test.CheckContextUnloaded(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.