Skip to content

Commit

Permalink
Redirect "System.Private.Xml.Linq" assembly to "System.Xml.Linq"
Browse files Browse the repository at this point in the history
This improves interoperability between .NET Core & .NET Framework. The former knows how to redirect types by default, but the latter doesn't.
Closes HangfireIO#2400
  • Loading branch information
odinserj committed Jun 7, 2024
1 parent 202e4ac commit 4bd4da9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Hangfire.Core/Common/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ private static Assembly AssemblyResolver(string assemblyString)
{
assemblyName = MscorlibAssemblyName;
}
else if (assemblyName.Name.Equals("System.Private.Xml.Linq", StringComparison.OrdinalIgnoreCase))
{
assemblyName = new AssemblyName("System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
}

var publicKeyToken = assemblyName.GetPublicKeyToken();

Expand Down
27 changes: 27 additions & 0 deletions tests/Hangfire.Core.Tests/Storage/InvocationDataFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,26 @@ public void DeserializePayload_WithQueueNameSet_ReturnsCorrectInvocationData(str
Assert.Equal("critical", invocationData.Queue);
}

[Fact]
public void Deserialize_CorrectlyHandles_SystemXmlLinqEntities_SerializedWithNETFramework()
{
var job = InvocationData.DeserializePayload(
"{\"t\":\"Hangfire.Core.Tests.Storage.InvocationDataFacts, Hangfire.Core.Tests\",\"m\":\"XmlLinqMethod\",\"p\":[\"System.Xml.Linq.XElement, System.Xml.Linq\"],\"a\":[\"{\\\"element\\\":\\\"This is a test\\\"}\"]}")
.DeserializeJob();

Assert.Equal(typeof(InvocationDataFacts), job.Type);
}

[Fact]
public void Deserialize_CorrectlyHandles_SystemXmlLinqEntities_SerializedWithNETCore()
{
var job = InvocationData.DeserializePayload(
"{\"t\":\"Hangfire.Core.Tests.Storage.InvocationDataFacts, Hangfire.Core.Tests\",\"m\":\"XmlLinqMethod\",\"p\":[\"System.Xml.Linq.XElement, System.Private.Xml.Linq\"],\"a\":[\"{\\\"element\\\":\\\"This is a test\\\"}\"]}")
.DeserializeJob();

Assert.Equal(typeof(InvocationDataFacts), job.Type);
}

private class FieldsOnlyContractResolver: DefaultContractResolver
{
protected override List<MemberInfo> GetSerializableMembers(Type objectType)
Expand Down Expand Up @@ -1022,6 +1042,13 @@ public static void NullableDateTimeMethod(DateTime? arg)
{
}

[UsedImplicitly]
[SuppressMessage("Usage", "xUnit1013:Public method should be marked as test")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static void XmlLinqMethod(System.Xml.Linq.XElement value)
{
}

public class GenericType<T1>
{
public void Method()
Expand Down

0 comments on commit 4bd4da9

Please sign in to comment.