Skip to content

Commit a29d417

Browse files
fix: allow assembly version to be ignored
1 parent 8c7ba5e commit a29d417

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/EntityDb.Common/TypeResolvers/DefaultPartialTypeResolver.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
using EntityDb.Common.Envelopes;
2+
using Microsoft.Extensions.Options;
23
using System.Diagnostics.CodeAnalysis;
34
using System.Reflection;
45

56
namespace EntityDb.Common.TypeResolvers;
67

78
internal class DefaultPartialTypeResolver : IPartialTypeResolver
89
{
10+
private readonly IOptions<DefaultPartialTypeResolverOptions> _options;
11+
12+
public DefaultPartialTypeResolver(IOptions<DefaultPartialTypeResolverOptions> options)
13+
{
14+
_options = options;
15+
}
16+
17+
private Assembly AssemblyResolver(AssemblyName assemblyName)
18+
{
19+
if (_options.Value.IgnoreVersion)
20+
{
21+
assemblyName.Version = null;
22+
}
23+
24+
return Assembly.Load(assemblyName);
25+
}
26+
927
public bool TryResolveType(EnvelopeHeaders envelopeHeaders, [NotNullWhen(true)] out Type? resolvedType)
1028
{
1129
if (EnvelopeHelper.NotThisPlatform(envelopeHeaders) ||
@@ -19,7 +37,7 @@ public bool TryResolveType(EnvelopeHeaders envelopeHeaders, [NotNullWhen(true)]
1937
resolvedType = Type.GetType
2038
(
2139
Assembly.CreateQualifiedName(assemblyFullName, typeFullName),
22-
Assembly.Load,
40+
AssemblyResolver,
2341
(assembly, typeName, ignoreCase) => assembly!.GetType(typeName, true, ignoreCase),
2442
true,
2543
false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace EntityDb.Common.TypeResolvers;
2+
3+
/// <summary>
4+
/// Options for the default partial type resolver
5+
/// </summary>
6+
public class DefaultPartialTypeResolverOptions
7+
{
8+
/// <summary>
9+
/// If you version your assemblies, you may want to ignore the
10+
/// version of the assembly for type resolving purposes.
11+
/// </summary>
12+
public bool IgnoreVersion { get; set; }
13+
}

0 commit comments

Comments
 (0)