Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ private PowerShellAssemblyLoadContext(string basePaths)
// - Value: strong name of the TPA that contains the type represented by Key.
private readonly Dictionary<string, string> _coreClrTypeCatalog;
private readonly Lazy<HashSet<string>> _availableDotNetAssemblyNames;
private readonly HashSet<string> _blackListedAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase){
"System.Windows.Forms"
};

#if !UNIX
private string _winDir;
Expand Down Expand Up @@ -295,6 +298,13 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
private bool TryFindInGAC(AssemblyName assemblyName, out string assemblyFilePath)
{
assemblyFilePath = null;
if (_blackListedAssemblies.Contains(assemblyName.Name))
{
// DotNet catches and throws a new exception with no inner exception
// We cannot change the message DotNet returns.
return false;
}

if (Internal.InternalTestHooks.DisableGACLoading)
{
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Assembly.LoadFrom Validation Test" -Tags "CI" {
BeforeAll {
$ConsumerCode = @'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Assembly::LoadWithPartialName Validation Test" -Tags "CI" {

$defaultErrorId = 'FileLoadException'
$testcases = @(
# verify winforms is blocked
@{
Name = 'system.windows.forms'
ErrorId = $defaultErrorId
}
# Verify alternative casing is blocked
@{
Name = 'System.Windows.Forms'
ErrorId = $defaultErrorId
}
)

# All existing cases should fail on all platforms either because it doesn't exist or
# because the assembly is blacklisted
It "Assembly::LoadWithPartialName should fail to load blacklisted assembly: <Name>" -TestCases $testcases {
param(
[Parameter(Mandatory)]
[string]
$Name,
[Parameter(Mandatory)]
[string]
$ErrorId
)

{[System.Reflection.Assembly]::LoadWithPartialName($Name)} | Should -Throw -ErrorId $ErrorId
}
}