如何解决Blazor WASM:引用System.ComponentModel.DataAnnotations会导致发行版本上的链接失败
我创建了一个新的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.
我知道如果禁用链接功能,我可以通过该错误,但是我不想这样做,因为我想减小下载量。
解决方法
我发现我不必引用System.ComponentModel.DataAnnotations.dll
,而必须使用同名的Nuget包,并且当我使用Nuget包时,可以消除链接错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。