Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17781


Ignore:
Timestamp:
11/18/20 10:58:03 (4 years ago)
Author:
jkarder
Message:

#3089: explicitly fail on ReflectionTypeLoadException and BadImageFormatException

Location:
trunk/HeuristicLab.Tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Tests/HeuristicLab-3.3/PluginDependenciesTest.cs

    r17180 r17781  
    3939    [ClassInitialize]
    4040    public static void MyClassInitialize(TestContext testContext) {
    41       loadedPlugins = PluginLoader.Assemblies.Where(PluginLoader.IsPluginAssembly).ToDictionary(a => a, GetPluginFromAssembly);
     41      try {
     42        loadedPlugins = PluginLoader.Assemblies.Where(PluginLoader.IsPluginAssembly).ToDictionary(a => a, GetPluginFromAssembly);
     43      } catch (BadImageFormatException e) {
     44        var message = string.Join(Environment.NewLine, "Could not load all types. Check if test process architecture is set to x64.", string.Empty, "Exception:", e);
     45        Assert.Fail(message);
     46      }
     47
    4248      pluginNames = loadedPlugins.ToDictionary(a => a.Key.GetName().FullName, a => GetPluginName(a.Value));
    4349
  • trunk/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs

    r17019 r17781  
    22using System.Collections.Generic;
    33using System.Linq;
     4using System.Reflection;
    45using HEAL.Attic;
    56using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    1617      var dict = new Dictionary<Guid, string>();
    1718      var duplicates = new Dictionary<string, string>();
    18       // using AppDomain instead of ApplicationManager so that NonDiscoverableTypes are also checked
    19       foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())) {
    20         var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
    21         if (attr == null)
    22           continue;
    2319
    24         foreach (var guid in attr.Guids) {
    25           if (!dict.ContainsKey(guid)) {
    26             dict.Add(guid, type.FullName);
    27           } else {
    28             duplicates.Add(type.FullName, dict[guid]);
     20      try {
     21        // using AppDomain instead of ApplicationManager so that NonDiscoverableTypes are also checked
     22        foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())) {
     23          var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
     24          if (attr == null)
     25            continue;
     26
     27          foreach (var guid in attr.Guids) {
     28            if (!dict.ContainsKey(guid)) {
     29              dict.Add(guid, type.FullName);
     30            } else {
     31              duplicates.Add(type.FullName, dict[guid]);
     32            }
    2933          }
    3034        }
     35      } catch (ReflectionTypeLoadException e) {
     36        var loaderExeptions = string.Join("-----" + Environment.NewLine, e.LoaderExceptions.Select(x => x.ToString()));
     37        var message = string.Join(Environment.NewLine, "Could not load all types. Check if test process architecture is set to x64.",
     38          string.Empty, "Exception:", e, string.Empty, "LoaderExceptions:", loaderExeptions);
     39        Assert.Fail(message);
    3140      }
    3241
Note: See TracChangeset for help on using the changeset viewer.