2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Reflection ;
5
- using System . Text ;
6
- using System . Threading . Tasks ;
7
5
8
6
namespace Zbu . ModelsBuilder
9
7
{
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
+
10
21
public static class AssemblyUtility
11
22
{
12
23
// fixme - this is slow and should probably be cached in a static var!
@@ -17,7 +28,7 @@ public static IEnumerable<string> GetAllReferencedAssemblyLocations()
17
28
var assemblies = new List < Assembly > ( ) ;
18
29
var tmp1 = new List < Assembly > ( ) ;
19
30
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 ) )
21
32
{
22
33
assemblies . Add ( assembly ) ;
23
34
tmp1 . Add ( assembly ) ;
0 commit comments