-
Notifications
You must be signed in to change notification settings - Fork 87
Ignore assembly version when activating DataProtection types from string name #223
Conversation
@@ -27,6 +27,8 @@ public SimpleActivator(IServiceProvider services) | |||
|
|||
public virtual object CreateInstance(Type expectedBaseType, string implementationTypeName) | |||
{ | |||
implementationTypeName = RemoveVersionFromAssemblyName(implementationTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets disable this on core.
|
||
private static string RemoveVersionFromAssemblyName(string typeName) | ||
{ | ||
var idx = typeName.IndexOf(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this fail on generic types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. I'll add a test to make sure
} | ||
|
||
// type name includes assembly name | ||
var assemblyName = typeName.Substring(idx + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be enabled only for predefined list of our assemblies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be a specific list or is AssemblyName.StartsWith("Microsoft.AspNetCore")
ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do just DataProtection assemblies.
using Microsoft.AspNetCore.DataProtection.Internal; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.DataProtection | ||
{ | ||
public class ActivatorTests | ||
public class ActivatorTests : MarshalByRefObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to make this work: AppDomain.CreateInstanceAndUnwrap.
…f type name is a generic
🆙 📅 |
Btw, I verified the end-to-end scenario manually using this project file and the code provided in #187 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<!--<PackageReference Include="Microsoft.AspNetCore.DataProtection.Extensions" Version="2.0.0-*"/>-->
<ProjectReference Include="../../src/Microsoft.AspNetCore.DataProtection.Extensions/Microsoft.AspNetCore.DataProtection.Extensions.csproj"/>
</ItemGroup>
</Project> |
@natemcmaster thanks for fixing this bug! 👏 |
Add a test to verify that version is not striped from non asp.net core assemblies. |
🆙 📅 |
…ing name on .NET Framework This is a port of #223 from the 2.0.0 release. It resolves an issue caused by activating types by type name. Type.GetType enforces the assembly version. This change strips assembly version before attempting to re-create DataProtection types.
…ing name on .NET Framework This is a port of #223 from the 2.0.0 release. It resolves an issue caused by activating types by type name. Type.GetType enforces the assembly version. This change strips assembly version before attempting to re-create DataProtection types.
…ing on .NET Framework. This is a port of #223 from the 2.0.0 release. It resolves an issue caused by activating types by type name. Type.GetType enforces the assembly version. This change strips assembly version before attempting to re-create DataProtection types.
…ing on .NET Framework. This is a port of #223 from the 2.0.0 release. It resolves an issue caused by activating types by type name. Type.GetType enforces the assembly version. This change strips assembly version before attempting to re-create DataProtection types.
Resolves #187 by ignoring assembly version in the code the rehydrates types from strings.
Incidental fixups: