Skip to content

Commit

Permalink
Exception handling for loading assemblies when GetAssemblies fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Edney committed Mar 25, 2019
1 parent d9953e8 commit 197b4a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 25 additions & 5 deletions src/DeployCmsData.Core/Data/UpgradeScriptRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using DeployCmsData.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using DeployCmsData.Core.Interfaces;

namespace DeployCmsData.Core.Data
{
Expand All @@ -10,7 +9,28 @@ public sealed class UpgradeScriptRepository : IUpgradeScriptRepository
IEnumerable<Type> IUpgradeScriptRepository.GetTypes =>
GetTypes;

public static IEnumerable<Type> GetTypes =>
AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes());
private IEnumerable<Type> GetTypes
{
get
{
var result = new List<Type>();
var assemblies = AppDomain.CurrentDomain.GetAssemblies();

foreach (var assembly in assemblies)
{
try
{
var assemblyTypes = assembly.GetTypes();
result.AddRange(assemblyTypes);
}
catch
{
// there was an error calling assembly.GetTypes() - there's nothing we can do
}
}

return result;
}
}
}
}
4 changes: 2 additions & 2 deletions src/DeployCmsData.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DeployCmsData.Core")]
[assembly: AssemblyDescription("Run code on startup")]
[assembly: AssemblyDescription("Upgrade script management for DeployCmsData")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Programystic")]
[assembly: AssemblyProduct("DeployCmsData.Core")]
Expand All @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.0")]
//[assembly: AssemblyInformationalVersion("1.0.1.0-beta")]

0 comments on commit 197b4a4

Please sign in to comment.