Category Archives: Core .NET

C# core development of all types (desktop, Silverlight, ASP.NET, etc.)

Adding Forms Authentication to Web API

Web API projects don’t ship with external (forms) authentication, but it’s not hard to graft them on. Using the MVC project code, we can easily add forms authentication to the Web API. Continue reading

Posted in Core .NET, Web | Tagged , | Leave a comment

Defeating Memory Editors with Moving Values

Want to prevent memory editing in your .NET games? I present a MovingValue class which you can use to store a value whose memory address changes on each write operation. Continue reading

Posted in Core .NET | Tagged | Leave a comment

Manually Rolling Back a TransactionScope

How do you rollback a TransactionScope instance? Well, with Dispose, oddly enough. Continue reading

Posted in Core .NET, Web | Tagged | Leave a comment

Powershell + InstallUtil: Unable to get installer types Error

Powershell gives an “unable to get installer types” error if you reference the v3.0 DLL instead of the v1.0 DLL in your project. Switch your reference to the 1.0 DLL and it should install without any issue. Continue reading

Posted in Core .NET, Tools | Tagged , | Leave a comment

Writing Automated Performance Tests

I found a memory leak in my application, and wrote an automated test using GC.GetTotalMemory to tell if objects were leaking or not. They were (20MB of them in 100k instances). Continue reading

Posted in Core .NET, Silverlight, Wndows Forms, WPF | Tagged , | Leave a comment

DriveInfo: Total vs. Available Free Space

DriveInfo.AvailableFreeSpace gives you free space with quotas applied; on the other hand, TotalFreeSpace gives you the total, physical amount of empty space on the drive. Continue reading

Posted in Core .NET, Wndows Forms | Tagged | Leave a comment

Running Windows Services in Visual Studio

You can run a project that’s a Windows service with an infinite loop (yes, really) by invoking the service and waiting. Forever. You can do this conditionally (while not debugging), instead of running ServiceBase.Run. Continue reading

Posted in Core .NET, Wndows Forms | Tagged | Leave a comment

Using Enumerations as Bit Flags

You can use enumerations as bit flags. The FlagsAttribute is optional; more importantly, you need to assign powers of 2^n to the enum’s values. Depending on the .NET version, checking can be easy (.HasFlag) or hard (bitwise AND operation) Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF | Tagged , | Leave a comment

Creating an Instance Without Using Constructors

You can create an instance of a class without calling any of its contructors, via a call to System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(A)). Scary, but useful in certain cases (like creating instances of highly-coupled or hard-to-instantiate classes in tests). Continue reading

Posted in Core .NET, Web, Wndows Forms | Tagged | Leave a comment

Storing a String List in App.Config or Web.Config

How can you store a list of strings (or ints, say) into a single appSetting key/value pair? Surprisingly, it’s as easy as using a delimited list (like comma-delimited or semicolon-delimited) and splitting it at runtime. Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF | Tagged , | Leave a comment