Skip to content

Commit 1cfb31f

Browse files
author
Stephan
committed
Prevent Roslyn from loading dynamic asm [#68]
1 parent ce90d66 commit 1cfb31f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Zbu.ModelsBuilder/AssemblyUtility.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5-
using System.Text;
6-
using System.Threading.Tasks;
75

86
namespace Zbu.ModelsBuilder
97
{
8+
// issue [#67]
9+
// GetAllReferencedAssemblyLocations throws on dynamic assemblies that would
10+
// be loaded in the current AppDomain, because these assemblies do not have
11+
// a location.
12+
// We can either fix it by either ignoring dynamic assemblies, or finding a
13+
// way to create a MetadataReference to an assembly that exists only in
14+
// memory.
15+
// Cannot find a way to create such a MetadataReference as it can only create
16+
// from the assembly's bytes, which we don't have. However, if the assembly
17+
// exists only in memory, it cannot really be referenced in a compilation,
18+
// so it should be fine to exclude it.
19+
// Fixing by adding .Where(x => x.IsDynamic == false)
20+
1021
public static class AssemblyUtility
1122
{
1223
// fixme - this is slow and should probably be cached in a static var!
@@ -17,7 +28,7 @@ public static IEnumerable<string> GetAllReferencedAssemblyLocations()
1728
var assemblies = new List<Assembly>();
1829
var tmp1 = new List<Assembly>();
1930
var failed = new List<AssemblyName>();
20-
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
31+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.IsDynamic == false))
2132
{
2233
assemblies.Add(assembly);
2334
tmp1.Add(assembly);

0 commit comments

Comments
 (0)