Skip to content

Commit

Permalink
Fixed the issue of temporary ASP.NET assemblies not being resolved co…
Browse files Browse the repository at this point in the history
…rrectly
  • Loading branch information
napernik committed Apr 26, 2017
1 parent b41542f commit c80e610
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Composite/AspNet/TempAssembliesFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Linq;
using System.Reflection;
using Composite.Core;
using Composite.Core.Application;

namespace Composite.AspNet
{
/// <summary>
/// Fixed the issue of temporary asp.net assemblies not being resolved correctly.
/// </summary>
[ApplicationStartup]
class TempAssembliesFix
{
public static void OnInitialized()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
}

private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
string asmName = args.Name;

if (!asmName.StartsWith("App_") || !asmName.Contains(","))
{
return null;
}

var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(asm => asm.FullName == asmName);
if (assembly != null)
{
return assembly;
}

Log.LogVerbose("OnAssemblyResolve", $"Failed to resolve assembly: {args.Name}"
+ (args.RequestingAssembly != null ? $", requesting assembly: '{args.RequestingAssembly.FullName}'" : ""));
return null;
}
}
}
1 change: 1 addition & 0 deletions Composite/Composite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<Compile Include="AspNet\SiteMapContext.cs" />
<Compile Include="AspNet\SiteMapHandler.cs" />
<Compile Include="AspNet\SiteMapNodeChangeFrequency.cs" />
<Compile Include="AspNet\TempAssembliesFix.cs" />
<Compile Include="AspNet\UserControlFunction.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
Expand Down

0 comments on commit c80e610

Please sign in to comment.