Skip to content

Commit

Permalink
Prevent Roslyn from loading dynamic asm [#68]
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan committed Sep 23, 2015
1 parent ce90d66 commit 1cfb31f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Zbu.ModelsBuilder/AssemblyUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Zbu.ModelsBuilder
{
// issue [#67]
// GetAllReferencedAssemblyLocations throws on dynamic assemblies that would
// be loaded in the current AppDomain, because these assemblies do not have
// a location.
// We can either fix it by either ignoring dynamic assemblies, or finding a
// way to create a MetadataReference to an assembly that exists only in
// memory.
// Cannot find a way to create such a MetadataReference as it can only create
// from the assembly's bytes, which we don't have. However, if the assembly
// exists only in memory, it cannot really be referenced in a compilation,
// so it should be fine to exclude it.
// Fixing by adding .Where(x => x.IsDynamic == false)

public static class AssemblyUtility
{
// fixme - this is slow and should probably be cached in a static var!
Expand All @@ -17,7 +28,7 @@ public static IEnumerable<string> GetAllReferencedAssemblyLocations()
var assemblies = new List<Assembly>();
var tmp1 = new List<Assembly>();
var failed = new List<AssemblyName>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.IsDynamic == false))
{
assemblies.Add(assembly);
tmp1.Add(assembly);
Expand Down

0 comments on commit 1cfb31f

Please sign in to comment.