I created a new Blazor WebAssembly project and just added a [Display] attribute to a property in a model in shared project:
using System;
using System.ComponentModel.DataAnnotations;
public class WeatherForecast
{
[Display(Name = "Temperature")]
public int TemperatureC { get; set; }
...
}
This requires to reference to System.ComponentModel.DataAnnotations.dll
. But when I do it and then press Build in Release mode, compiler throws this error:
5>C:\Users\Ali\.nuget\packages\microsoft.aspnetcore.components.webassembly.build\3.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Linker.MarkException: Error processing method: 'System.Void System.Configuration.ConfigurationErrorsException::.ctor(System.String,System.Exception,System.String,System.Int32)' in assembly: 'System.Configuration.dll'
5> ---> Mono.Cecil.ResolutionException: Failed to resolve System.Configuration.ConfigurationException
5> at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
5> at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
5> at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
5> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
5> at Mono.Linker.Steps.MarkStep.ProcessQueue()
5> --- End of inner exception stack trace ---
5> at Mono.Linker.Steps.MarkStep.ProcessQueue()
5> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
5> at Mono.Linker.Steps.MarkStep.Process()
5> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
5> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
5> at Mono.Linker.Pipeline.Process(LinkContext context)
5> at Mono.Linker.Driver.Run(ILogger customLogger)
5> at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
5> at Mono.Linker.Driver.Main(String[] args)
5>C:\Users\Ali\.nuget\packages\microsoft.aspnetcore.components.webassembly.build\3.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code -532462766.
I know I can pass the error if I disable linking feature but I don't want to do that because I want to reduce the size of downloads.
I found that instead of referencing to System.ComponentModel.DataAnnotations.dll
I have to use a Nuget package with the same name and when I used Nuget package, linking error eliminated.