为什么多次使用PreApplicationStartMethodAttribute不是';t已编译
本文关键字:编译 不是 PreApplicationStartMethodAttribute 为什么 | 更新日期: 2024-10-20 02:06:34
System.Web.PreApplicationStartMethodAttribute定义为:
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute
{}
也就是说,它允许多次使用(AllowMultiple=true)。但是,如果我尝试将此属性的几种用法添加到我的程序集中:
[assembly: PreApplicationStartMethod(typeof(MyType1), "Start")]
[assembly: PreApplicationStartMethod(typeof(MyType2), "Start")]
我得到编译器错误:
错误2重复的"PreApplicationStartMethod"属性
为什么
我怀疑您看到的是.NET 4.5版本,它被记录为具有AllowMultiple = True
。
.NET 4.0版本的文档将其显示为AllowMultiple = false
:
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute
所以,如果你的目标是.NET 4.5,那应该没问题。