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
7 changes: 7 additions & 0 deletions eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<_projectSourceFile>%(TestConsoleApps.ProjectCompileItems)</_projectSourceFile>
</PropertyGroup>

<ItemGroup>
<_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" />
</ItemGroup>

<MakeDir Directories="$(_projectDir)" />
<WriteLinesToFile File="$(_projectFile)"
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)')
Expand All @@ -68,6 +72,9 @@
Overwrite="true" />
<Copy SourceFiles="$(_projectSourceFile)"
DestinationFolder="$(_projectDir)" />
<Copy SourceFiles="@(_additionalProjectSourceFiles)"
DestinationFolder="$(_projectDir)"
Condition="'@(_additionalProjectSourceFiles)' != ''" />
<Message Text="Generated $(_projectFile)" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ private TypeDescriptor()
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static Type InterfaceType
{
// TODO: replace this with DynamicallyAccessedMembersAttribute (https://github.com/dotnet/runtime/issues/37837)
[DynamicDependency("#ctor", typeof(TypeDescriptorInterface))]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
get => typeof(TypeDescriptorInterface);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.ComponentModel;

/// <summary>
/// Tests that the System.ComponentModel.TypeDescriptor.InterfaceType
/// property works as expected when used in a trimmed application.
/// </summary>
class Program
{
static int Main(string[] args)
{
Type type = TypeDescriptor.InterfaceType;

// Tests that the ctor for System.ComponentModel.TypeDescriptor+TypeDescriptorInterface is not trimmed out.
object obj = Activator.CreateInstance(type);
string expectedObjTypeNamePrefix = "System.ComponentModel.TypeDescriptor+TypeDescriptorInterface, System.ComponentModel.TypeConverter, Version=";

return obj != null && obj.GetType().AssemblyQualifiedName.StartsWith(expectedObjTypeNamePrefix)
? 100
: -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ private static Func<Stream, XmlReaderSettings, XmlParserContext, XmlReader> Crea

private static MethodInfo CreateSqlReaderMethodInfo
{
[DynamicDependency("CreateSqlReader", typeof(System.Xml.XmlReader))]
get
{
if (s_createSqlReaderMethodInfo == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Dynamic.Utils;
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace System.Linq.Expressions.Interpreter
Expand Down Expand Up @@ -160,17 +160,7 @@ private static CallInstruction FastCreate<T0, T1>(MethodInfo target, ParameterIn
#endif

#if FEATURE_DLG_INVOKE
// TODO: replace these with DynamicallyAccessedMembersAttribute (https://github.com/dotnet/runtime/issues/37837)
[DynamicDependency("#ctor", typeof(ActionCallInstruction))]
[DynamicDependency("#ctor", typeof(ActionCallInstruction<>))]
[DynamicDependency("#ctor", typeof(ActionCallInstruction<,>))]
[DynamicDependency("#ctor", typeof(ActionCallInstruction<,,>))]
[DynamicDependency("#ctor", typeof(ActionCallInstruction<,,,>))]
[DynamicDependency("#ctor", typeof(FuncCallInstruction<>))]
[DynamicDependency("#ctor", typeof(FuncCallInstruction<,>))]
[DynamicDependency("#ctor", typeof(FuncCallInstruction<,,>))]
[DynamicDependency("#ctor", typeof(FuncCallInstruction<,,,>))]
[DynamicDependency("#ctor", typeof(FuncCallInstruction<,,,,>))]
[return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.PublicConstructors)]
private static Type GetHelperType(MethodInfo info, Type[] arrTypes)
{
Type t;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

/// <summary>
/// Tests that the System.Linq.Expressions.Interpreter.CallInstruction.GetHelperType
/// method works as expected when used in a trimmed application.
/// </summary>
internal class Program
{
static int Main(string[] args)
{
for (int rank = 1; rank < 6; rank++)
{
Array arrayObj = Array.CreateInstance(typeof(string), Enumerable.Repeat(1, rank).ToArray());
arrayObj.SetValue("solitary value", Enumerable.Repeat(0, rank).ToArray());
ConstantExpression array = Expression.Constant(arrayObj);
IEnumerable<DefaultExpression> indices = Enumerable.Repeat(Expression.Default(typeof(int)), rank);
// This code path for the Compile call excercises the method being tested.
Func<string> func = Expression.Lambda<Func<string>>(
Expression.ArrayAccess(array, indices)).Compile(preferInterpretation: true);

if (func() != "solitary value")
{
return -1;
}
}

return 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project DefaultTargets="Build">
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal static class CookieExtensions
{
private static Func<Cookie, string> s_toServerStringFunc;

[DynamicDependency("ToServerString", typeof(Cookie))]
public static string ToServerString(this Cookie cookie)
{
s_toServerStringFunc ??= (Func<Cookie, string>)typeof(Cookie).GetMethod("ToServerString", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func<Cookie, string>));
Expand All @@ -23,7 +22,6 @@ public static string ToServerString(this Cookie cookie)

private static Func<Cookie, Cookie> s_cloneFunc;

[DynamicDependency("Clone", typeof(Cookie))]
public static Cookie Clone(this Cookie cookie)
{
s_cloneFunc ??= (Func<Cookie, Cookie>)typeof(Cookie).GetMethod("Clone", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func<Cookie, Cookie>));
Expand All @@ -42,7 +40,6 @@ private enum CookieVariant

private static Func<Cookie, CookieVariant> s_getVariantFunc;

[DynamicDependency("get_Variant", typeof(Cookie))]
public static bool IsRfc2965Variant(this Cookie cookie)
{
s_getVariantFunc ??= (Func<Cookie, CookieVariant>)typeof(Cookie).GetProperty("Variant", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true).CreateDelegate(typeof(Func<Cookie, CookieVariant>));
Expand All @@ -55,7 +52,6 @@ internal static class CookieCollectionExtensions
{
private static Func<CookieCollection, Cookie, bool, int> s_internalAddFunc;

[DynamicDependency("InternalAdd", typeof(CookieCollection))]
public static int InternalAdd(this CookieCollection cookieCollection, Cookie cookie, bool isStrict)
{
s_internalAddFunc ??= (Func<CookieCollection, Cookie, bool, int>)typeof(CookieCollection).GetMethod("InternalAdd", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func<CookieCollection, Cookie, bool, int>));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Net;
using System.Threading.Tasks;

namespace CookieExtensionsTest
{
/// <summary>
/// Tests that the System.Net.CookieExtensions.Clone()
/// method works as expected when used in a trimmed application.
/// </summary>
internal class Program
{
static async Task<int> Main(string[] args)
{
var helper = new TestHelper();
HttpListenerResponse response = await helper.GetResponse();
var cookie = new Cookie("name", "value");
response.SetCookie(cookie);

// Cookies are cloned.
cookie.Value = "value3";
if (response.Cookies[0].Value != "value")
{
return -1;
}

return 100;
}
}
}
Loading