Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Client: Cache global state assemblies by name #486

Merged
merged 1 commit into from Jul 6, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,6 +38,9 @@ protected override Task<TargetCompilationConfiguration> HandleAsync (Agent agent
var globalStateType = evaluationContext.GlobalState.GetType ();
response.GlobalStateTypeName = globalStateType.FullName;

// TODO: Why is globalStateType.Assembly.Location null when you
// create a non-XF workbook after creating an XF workbook?

// HACK: This is a temporary fix to get iOS agent/app assemblies sent to the
// Windows client when using the remote sim.
var peImage = IncludePeImage && File.Exists (globalStateType.Assembly.Location)
Expand Down
Expand Up @@ -17,6 +17,7 @@
using Xamarin.Interactive.Core;
using Xamarin.Interactive.Logging;
using Xamarin.Interactive.Reflection;
using Xamarin.Interactive.Representations.Reflection;

using static Xamarin.Interactive.Compilation.InteractiveDependencyResolver;

Expand Down Expand Up @@ -145,6 +146,8 @@ public static async Task<RoslynCompilationWorkspace> CreateWorkspaceAsync (Clien

static Assembly netStandardAssembly;
static Assembly xiAssembly;
static Dictionary<RepresentedAssemblyName, Assembly> globalStateAssembliesByName =
new Dictionary<RepresentedAssemblyName, Assembly> ();

static Type ResolveHostObjectType (
InteractiveDependencyResolver dependencyResolver,
Expand Down Expand Up @@ -184,9 +187,16 @@ public static async Task<RoslynCompilationWorkspace> CreateWorkspaceAsync (Clien
Assembly globalStateAssembly;
if (globalStateAssemblyDef.Name.Name == "Xamarin.Interactive")
globalStateAssembly = xiAssembly;
else
globalStateAssembly = Assembly.ReflectionOnlyLoadFrom (
globalStateAssemblyCachePath ?? globalStateAssemblyDef.Content.Location);
else {
// Cache assemblies in case subsequent agents lead us to try to load from a different location later.
// For example, if you create an XF workbook, we'll resolve from the remote assembly cache. If you
// then create a non-XF workbook, we'll resolve locally because PEImage doesn't get set for some reason.
if (!globalStateAssembliesByName.TryGetValue (configuration.GlobalStateAssembly.Name, out globalStateAssembly)) {
globalStateAssembly = Assembly.ReflectionOnlyLoadFrom (
globalStateAssemblyCachePath ?? globalStateAssemblyDef.Content.Location);
globalStateAssembliesByName [configuration.GlobalStateAssembly.Name] = globalStateAssembly;
}
}

return globalStateAssembly.GetType (configuration.GlobalStateTypeName);
}
Expand Down