Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 981bfb4

Browse files
HEskandaritimbussmann
authored andcommitted
Catch exceptions when loading types (#23)
1 parent 1ea6874 commit 981bfb4

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/NServiceBus.FileBasedRouting/XmlRoutingFileParser.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Xml;
66
using System.Xml.Linq;
77
using System.Xml.Schema;
8+
using NServiceBus.Logging;
89

910
namespace NServiceBus.FileBasedRouting
1011
{
@@ -48,17 +49,34 @@ static IEnumerable<Type> GetAllMessageTypes(XElement endpointElement, string sin
4849

4950
var separatelyConfiguredCommands = handles
5051
?.Elements(singular)
51-
.Select(e => SelectCommand(e.Attribute("type").Value))
52+
.Select(e => FindMessageType(e.Attribute("type").Value))
53+
.Where(e => e != null)
5254
.ToArray() ?? Type.EmptyTypes;
5355

5456
var filteredCommands = handles?.Elements(plural).SelectMany(SelectMessages) ?? Type.EmptyTypes;
5557
var allCommands = separatelyConfiguredCommands.Concat(filteredCommands).Distinct();
5658
return allCommands;
5759
}
5860

59-
static Type SelectCommand(string typeName)
61+
static Type FindMessageType(string typeName)
6062
{
61-
return Type.GetType(typeName, true);
63+
Type msg = null;
64+
65+
try
66+
{
67+
msg = Type.GetType(typeName, true);
68+
}
69+
catch
70+
{
71+
//ignore
72+
}
73+
74+
if (msg == null)
75+
{
76+
logger.Warn($"Cannot add route for unknown type {typeName}.");
77+
}
78+
79+
return msg;
6280
}
6381

6482
static IEnumerable<Type> SelectMessages(XElement commandsElement)
@@ -81,6 +99,8 @@ static IEnumerable<Type> SelectMessages(XElement commandsElement)
8199

82100
return exportedTypes.Where(type => type.Namespace != null && type.Namespace.StartsWith(@namespace.Value));
83101
}
102+
84103
readonly XmlSchemaSet schema;
104+
static readonly ILog logger = LogManager.GetLogger(typeof(XmlRoutingFileParser));
85105
}
86106
}

0 commit comments

Comments
 (0)