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

Commit 462a63a

Browse files
SzymonPobiegatimbussmann
authored andcommitted
Do not throw if assembly cannot be loaded (#29)
1 parent 55d5df4 commit 462a63a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/NServiceBus.FileBasedRouting.Tests/XmlRoutingFileTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ public void It_provides_distinct_result_even_when_types_are_registered_multiple_
120120
CollectionAssert.AreEquivalent(new[] { typeof(A), typeof(B) }, configuration.Commands);
121121
}
122122

123+
[Test]
124+
public void It_does_not_throw_if_assembly_cannot_be_found()
125+
{
126+
const string xml = @"
127+
<endpoints>
128+
<endpoint name=""EndpointName"">
129+
<handles>
130+
<commands assembly = ""FooBar"" />
131+
</handles>
132+
</endpoint>
133+
</endpoints>
134+
";
135+
var configurations = GetConfigurations(xml);
136+
137+
Assert.AreEqual(1, configurations.Length);
138+
var configuration = configurations[0];
139+
Assert.AreEqual("EndpointName", configuration.LogicalEndpointName);
140+
}
141+
123142

124143
static EndpointRoutingConfiguration[] GetConfigurations(string xml)
125144
{

src/NServiceBus.FileBasedRouting/XmlRoutingFileParser.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,17 @@ static Type FindMessageType(string typeName)
8282
static IEnumerable<Type> SelectMessages(XElement commandsElement)
8383
{
8484
var assemblyName = commandsElement.Attribute("assembly").Value;
85-
var assembly = Assembly.Load(assemblyName);
85+
Assembly assembly;
86+
try
87+
{
88+
assembly = Assembly.Load(assemblyName);
89+
}
90+
catch
91+
{
92+
logger.Warn($"Cannot add route for unknown assembly {assemblyName}.");
93+
return Enumerable.Empty<Type>();
94+
}
95+
8696
var exportedTypes = assembly.ExportedTypes;
8797
var @namespace = commandsElement.Attribute("namespace");
8898
if (@namespace == null)

0 commit comments

Comments
 (0)