Disable compiler optimisation for a specific function or block of code (C#)

You can decorate a specific method (or a property getter/setter) with [MethodImpl(MethodImplOptions.NoOptimization)] and [MethodImpl(MethodImplOptions.NoInlining)], this will prevent the JITter from optimizing and inlining the method: [MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] private void MethodWhichShouldNotBeOptimized() { } However, there isn’t a way to apply this attribute to a block of code. Also NoOptimization attribute was added in .NET 3.5, … Read more

Allowing iteration without generating any garbage

First off, a number of people are pushing back on Olhovsky to suggest that this is worrying about nothing. Avoiding collection pressure is actually very important in some applications on some environments. The compact framework garbage collector has an unsophisticated policy; it triggers a collection every time 1000KB of memory has been allocated. Now suppose … Read more

How to get exe application name and version in C# Compact Framework

Getting the app name: System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; Getting the version: System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; You might want to use GetCallingAssembly() or getting the assembly by type (e.g. typeof(Program).Assembly) if your DLL is trying to get the EXE version and you don’t have immediate access to it. EDIT If you have a DLL and you need the name of the executable … Read more

NLog does not create a log file

I had this problem turned out that my log file was not being copied to my build directory. The NLog github page had the answer. (I’ve reformatted the paragraph a little for better readability.) https://github.com/NLog/NLog/wiki/Logging-troubleshooting NLog cannot find the configuration file. This can happen when the NLog.config file is configured with Build Action = None … Read more

tech