Skip to content

Commit

Permalink
Fix issue where the same component can be loaded in multiple ALC and …
Browse files Browse the repository at this point in the history
…cause cast issues (#669)

* Fix issue where the same authored component was getting loaded in different ALC causing type cast issues.

* Change bin directory to _build folder.
  • Loading branch information
manodasanW committed Jan 15, 2021
1 parent fb0e7ad commit f5a5255
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
16 changes: 5 additions & 11 deletions src/Authoring/WinRT.Host.Shim/Module.cs
Expand Up @@ -2,14 +2,8 @@
// to simplify deployment

using System;
using System.Collections.Generic;
using System.IO;
using System.Collections.Concurrent;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Windows.Foundation;
using WinRT;

#if !NETSTANDARD2_0
using System.Runtime.Loader;
Expand Down Expand Up @@ -69,13 +63,14 @@ private static class ActivationLoader
}
#else
private class ActivationLoader : AssemblyLoadContext
{
{
private static readonly ConcurrentDictionary<string, ActivationLoader> ALCMapping = new ConcurrentDictionary<string, ActivationLoader>();
private AssemblyDependencyResolver _resolver;

public static Assembly LoadAssembly(string targetAssembly)
{
var loader = new ActivationLoader(targetAssembly);
return loader.LoadFromAssemblyPath(targetAssembly);
return ALCMapping.GetOrAdd(targetAssembly, (_) => new ActivationLoader(targetAssembly))
.LoadFromAssemblyPath(targetAssembly);
}

private ActivationLoader(string path)
Expand All @@ -96,7 +91,6 @@ private ActivationLoader(string path)
};
}


protected override Assembly Load(AssemblyName assemblyName)
{
if (assemblyName.Name != "WinRT.Runtime")
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Expand Up @@ -36,7 +36,7 @@
<CsWinRTPath Condition="'$(Platform)'=='ARM' or '$(Platform)'=='ARM64'">$([MSBuild]::NormalizeDirectory('$(SolutionDir)_build', 'x86', '$(Configuration)', 'cswinrt', 'bin'))</CsWinRTPath>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj' or '$(MSBuildProjectExtension)' == '.wapproj'">
<OutDir>$([MSBuild]::NormalizeDirectory('$(BuildOutDir)', '$(MSBuildProjectName)', 'bin'))</OutDir>
<IntDir>$([MSBuild]::NormalizeDirectory('$(BuildOutDir)', '$(MSBuildProjectName)', 'obj'))</IntDir>
</PropertyGroup>
Expand Down
8 changes: 2 additions & 6 deletions src/Tests/AuthoringConsumptionTest/test.cpp
Expand Up @@ -308,9 +308,7 @@ TEST(AuthoringTest, CustomDictionaryImplementations)

EXPECT_EQ(dictionary.GetView().TryLookup(L"second").value(), basicStruct2);
EXPECT_FALSE(dictionary.GetView().TryLookup(L"fourth").has_value());

// TODO: Broken due to ALC type mismatch.
/*

TestClass testClass;
EXPECT_EQ(testClass.GetSum(dictionary, L"second"), 4);

Expand All @@ -330,15 +328,13 @@ TEST(AuthoringTest, CustomDictionaryImplementations)
EXPECT_TRUE(mapSplit1.HasKey(L"first"));
EXPECT_FALSE(mapSplit1.HasKey(L"third"));
EXPECT_TRUE(mapSplit2.HasKey(L"third"));
*/

Windows::Foundation::Collections::IMap<hstring, AuthoringTest::BasicStruct> map = dictionary;
map.Clear();
EXPECT_EQ(map.Size(), 0);
}

// TODO: Broken due to ALC type mismatch.
TEST(AuthoringTest, DISABLED_CustomVectorImplementations)
TEST(AuthoringTest, CustomVectorImplementations)
{
TestClass testClass;
testClass.SetProjectedDisposableObject();
Expand Down

0 comments on commit f5a5255

Please sign in to comment.