Revised for latest .NET/MSVC.