为什么不编译多次使用PreApplicationStartMethodAttribute? [英] Why multiple using of PreApplicationStartMethodAttribute isn't compiled?
问题描述
System.Web.PreApplicationStartMethodAttribute定义为:
System.Web.PreApplicationStartMethodAttribute defined as:
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute
{}
即它允许多次使用(AllowMultiple = true). 但是,如果我尝试将这个属性的几种用法添加到我的程序集中:
I.e. it allows multiple usage (AllowMultiple=true). But if I try to added several usages of this attribute to my assembly :
[assembly: PreApplicationStartMethod(typeof(MyType1), "Start")]
[assembly: PreApplicationStartMethod(typeof(MyType2), "Start")]
我收到编译器错误:
错误2复制了'PreApplicationStartMethod'属性
Error 2 Duplicate 'PreApplicationStartMethod' attribute
这是为什么?
推荐答案
I suspect you were looking at the .NET 4.5 version, which is documented as having AllowMultiple = True
.
.NET 4.0版本的文档将其显示为
The documentation for the .NET 4.0 version shows it as AllowMultiple = false
:
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute
因此,如果您以.NET 4.5为目标,那应该没问题.
So if you target .NET 4.5, it should be okay.
这篇关于为什么不编译多次使用PreApplicationStartMethodAttribute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!