Permalink
Browse files

Changes to private assembly loading. Fixes #953 and allows in place u…

…pdates
  • Loading branch information...
1 parent e00d42c commit 94d066038eddfc5e6360b28f4ef267956992446e @fabiocav committed Dec 9, 2016
@@ -154,9 +154,10 @@ private FunctionAssemblyLoadContext GetFunctionContext(Assembly requestingAssemb
private FunctionAssemblyLoadContext GetFunctionContextFromDependency(Assembly requestingAssembly)
{
// If this is a private reference, get the context based on the CodeBase
- if (Uri.IsWellFormedUriString(requestingAssembly.CodeBase, UriKind.RelativeOrAbsolute))
+ string assemblyCodeBase = requestingAssembly.GetCodeBase();
+ if (Uri.IsWellFormedUriString(assemblyCodeBase, UriKind.RelativeOrAbsolute))
{
- var codebaseUri = new Uri(requestingAssembly.CodeBase, UriKind.RelativeOrAbsolute);
+ var codebaseUri = new Uri(assemblyCodeBase, UriKind.RelativeOrAbsolute);
if (_rootScriptUri.IsBaseOf(codebaseUri))
{
@@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Security.Policy;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Script.Extensibility;
@@ -222,8 +223,12 @@ public Assembly ResolveAssembly(string assemblyName)
// When loading shared assemblies, load into the load-from context and load assembly dependencies
assembly = Assembly.LoadFrom(assemblyPath);
}
- else if (TryResolvePrivateAssembly(assemblyName, out assemblyPath) ||
- _packageAssemblyResolver.TryResolveAssembly(assemblyName, out assemblyPath))
+ else if (TryResolvePrivateAssembly(assemblyName, out assemblyPath))
+ {
+ assembly = Assembly.Load(File.ReadAllBytes(assemblyPath));
+ assembly.MapCodeBase(assemblyPath);
+ }
+ else if (_packageAssemblyResolver.TryResolveAssembly(assemblyName, out assemblyPath))
{
// Use LoadFile here to load into the correct context
assembly = Assembly.LoadFile(assemblyPath);
@@ -0,0 +1,31 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for license information.
+
+using System;
+using System.Collections.Concurrent;
+using System.Reflection;
+
+namespace Microsoft.Azure.WebJobs.Script
+{
+ public static class AssemblyExtensions
+ {
+ private readonly static ConcurrentDictionary<Assembly, string> _codeBaseMapping = new ConcurrentDictionary<Assembly, string>();
+
+ public static bool MapCodeBase(this Assembly assembly, string codeBasePath)
+ {
+ var uri = new Uri(codeBasePath);
+ return _codeBaseMapping.TryAdd(assembly, uri.AbsoluteUri);
+ }
+
+ public static string GetCodeBase(this Assembly assembly)
+ {
+ string codeBase;
+ if (_codeBaseMapping.TryGetValue(assembly, out codeBase))
+ {
+ return codeBase;
+ }
+
+ return assembly.CodeBase;
+ }
+ }
+}
@@ -406,6 +406,7 @@
<Compile Include="Diagnostics\MetricsLogger.cs" />
<Compile Include="Diagnostics\HostStartedEvent.cs" />
<Compile Include="EnvironmentSettingNames.cs" />
+ <Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
<Compile Include="Extensions\FileUtility.cs" />
<Compile Include="Extensions\HttpRequestMessageExtensions.cs" />

0 comments on commit 94d0660

Please sign in to comment.