我创建了一个新的Blazor WebAssembly项目,并刚刚向共享项目中的模型中的属性添加了[Display]属性:
using System;
using System.ComponentModel.DataAnnotations;
public class WeatherForecast
{
[Display(Name = "Temperature")]
public int TemperatureC { get; set; }
...
}
这需要引用System.ComponentModel.DataAnnotations.dll
。但是当我这样做并在发布模式下按Build时,编译器会抛出此错误:
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.
我知道如果禁用链接功能,我可以通过该错误,但是我不想这样做,因为我想减小下载量。
答案 0 :(得分:0)
我发现我不必引用System.ComponentModel.DataAnnotations.dll
,而必须使用同名的Nuget包,并且当我使用Nuget包时,可以消除链接错误。