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 … Read more

Fluent NHibernate – Create database schema only if not existing

You can just use SchemaUpdate instead, it will update the schema if it exists and create it if it does not: public NhibernateSessionFactory(IPersistenceConfigurer config) { _sessionFactory = Fluently.Configure(). Database(config). Mappings(m => m.FluentMappings.AddFromAssemblyOf<MappingsPersistenceModel>()). ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true)). BuildSessionFactory(); } One caveat: SchemaUpdate does not do destructive updates (dropping tables, columns, etc.). It will only add … Read more

Assigning a GUID in C#

If you already have a string representation of the Guid, you can do this: Guid g = new Guid(“11223344-5566-7788-99AA-BBCCDDEEFF00”); And if you want a brand new Guid then just do Guid g = Guid.NewGuid();

Can method parameters be dynamic in C#

Yes, you can absolutely do that. For the purposes of static overload resolution, it’s treated as an object parameter (and called statically). What you do within the method will then be dynamic. For example: using System; class Program { static void Foo(dynamic duck) { duck.Quack(); // Called dynamically } static void Foo(Guid ignored) { } … Read more

The directory ‘/website/App_Code/’ is not allowed because the application is precompiled

Depending on your case, there are three possible scenarios: see this link http://www.beansoftware.com/ASP.NET-FAQ/Directory-App_Code-Not-Allowed.aspx Basically, If you precompiled your app, there shoudn’t be an App_Code folder. If you added it later, you should delete it. OR May be Somehow a precompiled.config file has made it to production. Deleting that file should resolve the App_Code directory error.

Why does field declaration with duplicated nested type in generic class results in huge source code increase?

The core of your question is why Inner.Inner is a different type than Inner. Once you understand that, your observations about compile time and generated IL code size follow easily. The first thing to note is that when you have this declaration public class X<T> { public class Y { } } There are infinitely … Read more