Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tracer/src/Datadog.Trace/DuckTyping/DuckType.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public static partial class DuckType
Type returnType = targetField.FieldType;

// Load the field value to the stack
if (UseDirectAccessTo(proxyTypeBuilder, targetType))
// Use targetField.DeclaringType (not targetType) to ensure IgnoresAccessChecksToAttribute
// is added for the assembly that actually owns the field. When targetType is a derived type
// in a different assembly, using targetType would miss the base type's assembly.
if (UseDirectAccessTo(proxyTypeBuilder, targetField.DeclaringType ?? targetType))
{
// Load the instance
if (!targetField.IsStatic)
Expand Down Expand Up @@ -212,7 +215,9 @@ public static partial class DuckType
}

// We set the field value
if (UseDirectAccessTo(proxyTypeBuilder, targetType))
// Use targetField.DeclaringType (not targetType) to ensure IgnoresAccessChecksToAttribute
// is added for the assembly that actually owns the field.
if (UseDirectAccessTo(proxyTypeBuilder, targetField.DeclaringType ?? targetType))
{
// If the instance and the field are public then is easy to set.
il.WriteTypeConversion(currentValueType, targetField.FieldType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,24 @@ public void GetUrl_ShouldFormatCorrectly(string url, bool useQueryManager, bool
var result = HttpRequestUtils.GetUrl(uri, queryStringManager);
result.Should().Be(expected);
}

[Theory]
[InlineData("http://localhost/path", "http://localhost/path")]
[InlineData("https://example.com/api/users?id=123", "https://example.com/api/users")]
[InlineData("http://localhost:8080/test", "http://localhost:8080/test")]
public void GetUrl_WithDerivedUri_ShouldFormatCorrectly(string url, string expected)
{
var uri = new DerivedUri(url);

var result = HttpRequestUtils.GetUrl(uri);
result.Should().Be(expected);
}

private class DerivedUri : Uri
{
public DerivedUri(string uriString)
: base(uriString)
{
}
}
}
Loading