Strange thing happening to me with the PreApplicationStartMethod Attribute. I did implement it in my latest project. In the AssemblyInfo.cs I have the following line:
[assembly: PreApplicationStartMethod(typeof(MyAssembly.Initializer), "Initialize")]
The Type and method look like this:
namespace MyAssembly
{
public static class Initializer
{
public static void Initialize()
{
TranslationKeys.Initialize();
}
}
}
When I rebuild my application and load it in the browser I get the following error:
The method specified by the PreApplicationStartMethodAttribute on assembly ‘MyWebApp, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null’ cannot be resolved. Type: ‘MyAssembly.Initializer’, MethodName: ‘Initialize’. Verify that the type is public and the method is public and static (Shared in Visual Basic).
I really have no idea what the problem is.
Strange, we use this feature a lot in the ASP.NET team, and have not run into this. To help debug this, can you try running the following code, which does something similar to what ASP.NET does to locate the method?
The best way to run it is to create a Console app and put that code in there. Then just call it, passing it the assembly where you are seeing the issue. You’ll then want to debug it and trace through it carefully to see what goes on.
BTW, before doing this, double check that you are putting the attribute on the same assembly that contains the class. i.e. it can’t point to a type in a different assembly.
Here is the code to try: