Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Ignore assembly version when activating DataProtection types from string name #223

Merged
merged 3 commits into from
Apr 25, 2017

Conversation

natemcmaster
Copy link
Contributor

Resolves #187 by ignoring assembly version in the code the rehydrates types from strings.

Incidental fixups:

  • register activator in DI with TryAddSingleton
  • update Redis package to 0.3.0. It was building as 0.1.0, even though 0.1.1 has been released

@@ -27,6 +27,8 @@ public SimpleActivator(IServiceProvider services)

public virtual object CreateInstance(Type expectedBaseType, string implementationTypeName)
{
implementationTypeName = RemoveVersionFromAssemblyName(implementationTypeName);
Copy link
Contributor

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(',');
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

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.

@natemcmaster
Copy link
Contributor Author

🆙 📅

@natemcmaster natemcmaster changed the title Ignore assembly version when activating types from string name Ignore assembly version when activating DataProtection types from string name Apr 20, 2017
@natemcmaster
Copy link
Contributor Author

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>

@kevinchalet
Copy link

@natemcmaster thanks for fixing this bug! 👏

@pakrym
Copy link
Contributor

pakrym commented Apr 24, 2017

Add a test to verify that version is not striped from non asp.net core assemblies.

@natemcmaster
Copy link
Contributor Author

🆙 📅

@natemcmaster natemcmaster merged commit 4dad47e into dev Apr 25, 2017
@natemcmaster natemcmaster deleted the namc/version branch April 25, 2017 21:29
natemcmaster pushed a commit that referenced this pull request Aug 25, 2017
…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.
natemcmaster pushed a commit that referenced this pull request Aug 25, 2017
…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.
natemcmaster pushed a commit that referenced this pull request Aug 25, 2017
…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.
natemcmaster pushed a commit that referenced this pull request Aug 28, 2017
…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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants