Changeset 11477


Ignore:
Timestamp:
10/17/14 10:44:42 (8 years ago)
Author:
mkommend
Message:

#2262: Refactored Script.GetAssemblies to get rid of the try/catch block.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting/3.3/Script.cs

    r10857 r11477  
    2424using System.CodeDom.Compiler;
    2525using System.Collections.Generic;
     26using System.Diagnostics;
    2627using System.Drawing;
    2728using System.IO;
     
    142143
    143144    public virtual IEnumerable<Assembly> GetAssemblies() {
    144       var assemblies = new List<Assembly>();
    145       foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
    146         try {
    147           if (File.Exists(a.Location)) assemblies.Add(a);
    148         } catch (NotSupportedException) {
    149           // NotSupportedException is thrown while accessing
    150           // the Location property of the anonymously hosted
    151           // dynamic methods assembly, which is related to
    152           // LINQ queries
    153         }
    154       }
     145      var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && File.Exists(a.Location)).ToList();   
    155146      assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality
    156147      return assemblies;
Note: See TracChangeset for help on using the changeset viewer.