Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does PreApplicationStartMethodAttribute() not work in SharePoint 2013?
    primarykey
    data
    text
    <p>In .NET 4(.5) there is this amazing <code>Attribute</code>: <a href="http://msdn.microsoft.com/en-us/library/ee818829.aspx" rel="nofollow"><code>PreApplicationStartMethodAttribute</code></a>, I want to use it in SharePoint 2013 so I don't have to edit the <code>app_start</code> method in the <code>global.asax</code> file directly.</p> <p>Since SP2013 runs the correct version of .NET I assumed that this attribute would just work... but this seems not to be the case.</p> <p>Has anyone figured out how to use it yet? or explain why it cannot work?</p> <p><strong>Small update</strong>: In the system.web dll I can see <a href="http://msdn.microsoft.com/en-us/library/ee818829.aspx" rel="nofollow"><code>PreApplicationStartMethodAttribute</code></a> is called by the folowing class.</p> <pre><code>// System.Web.Compilation.BuildManager internal static ICollection&lt;MethodInfo&gt; GetPreStartInitMethodsFromAssemblyCollection(IEnumerable&lt;Assembly&gt; assemblies, bool buildingFromCache) { List&lt;MethodInfo&gt; list = new List&lt;MethodInfo&gt;(); foreach (Assembly current in assemblies) { PreApplicationStartMethodAttribute[] array = null; try { array = (PreApplicationStartMethodAttribute[])current.GetCustomAttributes(typeof(PreApplicationStartMethodAttribute), true); } catch { } if (array == null || !array.Any&lt;PreApplicationStartMethodAttribute&gt;()) { if (buildingFromCache) { return null; } } else { PreApplicationStartMethodAttribute[] array2 = array; for (int i = 0; i &lt; array2.Length; i++) { PreApplicationStartMethodAttribute preApplicationStartMethodAttribute = array2[i]; MethodInfo methodInfo = null; if (preApplicationStartMethodAttribute.Type != null &amp;&amp; !string.IsNullOrEmpty(preApplicationStartMethodAttribute.MethodName) &amp;&amp; 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; } </code></pre> <p>If SharePoint 2013 is running on asp.net 4.0 I might have some luck invoking the following on the applicaton.</p> <pre><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload