Difference between Assembly.GetExecutingAssembly() and typeof(program).Assembly

Assuming program is in the executing assembly, they should both return the same value. However, typeof(program).Assembly should have better performance, since Assembly.GetExecutingAssembly() does a stack walk. In a micro benchmark on my machine, the former took about 20ns, while the latter was 30x slower at about 600ns.

If you control all the code I think you should always use typeof(program).Assembly. If you provided source code that other people could build into their assemblies, you would need to use Assembly.GetExecutingAssembly().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)