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

Commit

Permalink
Client: Cache global state assemblies by name
Browse files Browse the repository at this point in the history
1. Open Workbooks
2. Create a XF iOS workbook
3. Create a non-XF iOS workbook

The second workbook, for whatever reason, doesn't set a PEImage for the
global state assembly, so the client tries to resolve it from a different
location, leading to an exception.

Cache to avoid this. Will be nice when this reflection loading can go away.
  • Loading branch information
sandyarmstrong authored and abock committed Jul 6, 2018
1 parent 868164b commit 8d0d198
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ static InteractiveDependencyResolver CreateDependencyResolver (

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 @@ static Type ResolveHostObjectType (
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

0 comments on commit 8d0d198

Please sign in to comment.