In the bellow code for line
ConstructorInfo constructorInfoObj = ValueType.GetConstructor(Type.EmptyTypes);
I get this warning:
ValueDescriptor.cs(58, 50): [IL2080] 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.GetConstructor(Type[])'. The field 'MigraDocCore.DocumentObjectModel.Internals.ValueDescriptor.ValueType' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
This only occurs if I add
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
to the .csproj-file.
Why is this warning thrown, and what has it to do with trimmable ?
How to remedy this without removing IsTrimmable
and without setting EnableTrimAnalyzer
to false ?
This is the code for context:
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
namespace MigraDocCore.DocumentObjectModel.Internals
{
/// <summary>
/// Base class of all value descriptor classes.
/// </summary>
public abstract class ValueDescriptor
{
public Type ValueType;
internal ValueDescriptor(Type valueType)
{
this.ValueType = valueType;
}
public object CreateValue()
{
ConstructorInfo constructorInfoObj = ValueType.GetConstructor(Type.EmptyTypes);
return constructorInfoObj.Invoke(null);
}
// [...]
}
}
Full source of this class: https://github.com/ststeiger/PdfSharpCore/blob/master/MigraDocCore.DocumentObjectModel/MigraDoc.DocumentObjectModel.Internals/ValueDescriptor.cs#L58