In .NET 4(.5) there is this amazing Attribute
: PreApplicationStartMethodAttribute
,
I want to use it in SharePoint 2013 so I don't have to edit the app_start
method in the global.asax
file directly.
Since SP2013 runs the correct version of .NET I assumed that this attribute would just work... but this seems not to be the case.
Has anyone figured out how to use it yet? or explain why it cannot work?
Small update:
In the system.web dll I can see PreApplicationStartMethodAttribute
is called by the folowing class.
// System.Web.Compilation.BuildManager
internal static ICollection<MethodInfo> GetPreStartInitMethodsFromAssemblyCollection(IEnumerable<Assembly> assemblies, bool buildingFromCache)
{
List<MethodInfo> list = new List<MethodInfo>();
foreach (Assembly current in assemblies)
{
PreApplicationStartMethodAttribute[] array = null;
try
{
array = (PreApplicationStartMethodAttribute[])current.GetCustomAttributes(typeof(PreApplicationStartMethodAttribute), true);
}
catch
{
}
if (array == null || !array.Any<PreApplicationStartMethodAttribute>())
{
if (buildingFromCache)
{
return null;
}
}
else
{
PreApplicationStartMethodAttribute[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
PreApplicationStartMethodAttribute preApplicationStartMethodAttribute = array2[i];
MethodInfo methodInfo = null;
if (preApplicationStartMethodAttribute.Type != null && !string.IsNullOrEmpty(preApplicationStartMethodAttribute.MethodName) && preApplicationStartMethodAttribute.Type.Assembly == current)
{
methodInfo = BuildManager.FindPreStartInitMethod(preApplicationStartMethodAttribute.Type, preApplicationStartMethodAttribute.MethodName);
}
if (!(methodInfo != null))
{
throw new HttpException(SR.GetString("Invalid_PreApplicationStartMethodAttribute_value", new object[]
{
current.FullName,
(preApplicationStartMethodAttribute.Type != null) ? preApplicationStartMethodAttribute.Type.FullName : string.Empty,
preApplicationStartMethodAttribute.MethodName
}));
}
list.Add(methodInfo);
}
}
}
return list;
}
If SharePoint 2013 is running on asp.net 4.0 I might have some luck invoking the following on the applicaton.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe