Skip to content

Commit

Permalink
Add Assembly.LoadFrom() fallback in AssemblyCatalog
Browse files Browse the repository at this point in the history
Fixes #27433
  • Loading branch information
MarcoRossignoli authored and weshaggard committed Mar 22, 2018
1 parent ce4ebdf commit 32079aa
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ComponentModel.Compo
{2D694AC8-A12F-4622-9405-74E20EC40C3A} = {2D694AC8-A12F-4622-9405-74E20EC40C3A}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ComponentModel.Composition.Noop.Assembly", "tests\System.ComponentModel.Composition.Noop.Assembly\System.ComponentModel.Composition.Noop.Assembly.csproj", "{396D6EBF-60BD-4DAF-8783-FB403E070A56}"
ProjectSection(ProjectDependencies) = postProject
{2D694AC8-A12F-4622-9405-74E20EC40C3A} = {2D694AC8-A12F-4622-9405-74E20EC40C3A}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ComponentModel.Composition", "src\System.ComponentModel.Composition.csproj", "{2D694AC8-A12F-4622-9405-74E20EC40C3A}"
ProjectSection(ProjectDependencies) = postProject
{DD3B8052-CE03-4159-8311-1CE1382C51B0} = {DD3B8052-CE03-4159-8311-1CE1382C51B0}
Expand All @@ -30,6 +35,10 @@ Global
{59F4682D-C41D-45A7-9798-16C75525BB1D}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{59F4682D-C41D-45A7-9798-16C75525BB1D}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{59F4682D-C41D-45A7-9798-16C75525BB1D}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{396D6EBF-60BD-4DAF-8783-FB403E070A56}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{396D6EBF-60BD-4DAF-8783-FB403E070A56}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{396D6EBF-60BD-4DAF-8783-FB403E070A56}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{396D6EBF-60BD-4DAF-8783-FB403E070A56}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{2D694AC8-A12F-4622-9405-74E20EC40C3A}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{2D694AC8-A12F-4622-9405-74E20EC40C3A}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{2D694AC8-A12F-4622-9405-74E20EC40C3A}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
Expand All @@ -44,6 +53,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{59F4682D-C41D-45A7-9798-16C75525BB1D} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{396D6EBF-60BD-4DAF-8783-FB403E070A56} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{2D694AC8-A12F-4622-9405-74E20EC40C3A} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{DD3B8052-CE03-4159-8311-1CE1382C51B0} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading;
using Microsoft.Internal;
Expand Down Expand Up @@ -566,7 +567,15 @@ private static Assembly LoadAssembly(string codeBase)
assemblyName.CodeBase = codeBase;
}

return Assembly.Load(assemblyName);
try
{
return Assembly.Load(assemblyName);
}
//fallback attempt issue https://github.com/dotnet/corefx/issues/27433
catch (FileNotFoundException)
{
return Assembly.LoadFrom(codeBase);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{396D6EBF-60BD-4DAF-8783-FB403E070A56}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="TestClass.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace System.ComponentModel.Composition.Noop.Assembly
{
[Export]
public class TestClass
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,15 @@
<Compile Include="TestAssembly.cs" />
<Compile Include="TransparentTestCase.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="System.ComponentModel.Composition.Noop.Assembly/System.ComponentModel.Composition.Noop.Assembly.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1081,5 +1081,18 @@ public void ToString_ShouldReturnICompositionElementDisplayName()
Assert.Equal(catalog.DisplayName, catalog.ToString());
}
}

[Fact]
public void NonStaticallyReferencedAssembly()
{
string testAssembly = "System.ComponentModel.Composition.Noop.Assembly.dll";
var directory = TemporaryFileCopier.GetNewTemporaryDirectory();
Directory.CreateDirectory(directory);
var finalPath = Path.Combine(directory, testAssembly);
var sourcePath = Path.Combine(Directory.GetCurrentDirectory(), testAssembly);
File.Copy(sourcePath, finalPath);
var assemblyCatalog = new AssemblyCatalog(finalPath);
Assert.NotEmpty(assemblyCatalog);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ public void LoadedFiles_ContainsMultipleDllsAndSomeNonDll_ShouldOnlyContainDlls(
cat.LoadedFiles);
}

[Fact]
public void LoadedFiles_NonStaticallyReferencedAssembly()
{
string testAssembly = "System.ComponentModel.Composition.Noop.Assembly.dll";
var directory = TemporaryFileCopier.GetNewTemporaryDirectory();
Directory.CreateDirectory(directory);
var finalPath = Path.Combine(directory, testAssembly);
var sourcePath = Path.Combine(Directory.GetCurrentDirectory(), testAssembly);
File.Copy(sourcePath, finalPath);
var catalog = new DirectoryCatalog(directory, "*.dll");
Assert.NotEmpty(catalog);
}

[Fact]
public void Constructor_InvalidAssembly_ShouldBeFine()
{
Expand Down

0 comments on commit 32079aa

Please sign in to comment.