Skip to content

Commit

Permalink
Improved Unknown Assembly Experience/Messaging (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo authored Oct 26, 2021
1 parent 9d16a89 commit c341ecf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/ExtendedXmlSerializer/ReflectionModel/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Assembly Get(string parameter)
{
return Assembly.LoadFile(_path(parameter));
}
catch
catch (Exception error)
{
var length = _loaded.Length;
for (var i = 0; i < length; i++)
Expand All @@ -44,9 +44,7 @@ public Assembly Get(string parameter)
}
}

#pragma warning disable CS0618
return Assembly.LoadWithPartialName(parameter);
#pragma warning restore CS0618
throw new InvalidOperationException($"Could not load assembly '{parameter}'. Are you sure it exists?", error);
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue558Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using System;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue558Tests
{
[Fact]
public void Verify()
{
var subject = new ConfigurationContainer().Create().ForTesting();

const string document =
@"<?xml version=""1.0"" encoding=""utf-8""?><Issue558Tests-Subject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ReportedIssues;assembly=ExtendedXmlSerializer.Tests.ReportedIssues.DoesNotExist"" />";

subject.Invoking(x => x.Deserialize<Subject>(document))
.Should()
.ThrowExactly<InvalidOperationException>()
.WithMessage("Could not load assembly 'ExtendedXmlSerializer.Tests.ReportedIssues.DoesNotExist'. Are you sure it exists?");
}

sealed class Subject {}
}
}

0 comments on commit c341ecf

Please sign in to comment.