Posts about .NET Framework

TLS 1.2 support in .NET framework

May 19th 2023 .NET Framework

With new .NET (Core) versions being released every year, we might quickly forget that there are still many old .NET framework applications in use without being regularly updated. Recently I helped to fix one such application as it suddenly stopped working because of a failing SSL/TLS connection.

Compiling and Executing Code in a C# App

August 2nd 2019 Roslyn .NET .NET Framework

Since the release of Roslyn, the complete C# compiler pipeline is available as a NuGet package and we can include it in our own application. I was wondering how difficult it would be to use it to compile some C# source code into an executable and run it.

My Book About C# and .NET Is Available

February 1st 2019 Book C# .NET Framework .NET

Since this week, The Absolutely Awesome Book on C# and .NET is finally available for order in its final form: in all eBook formats and with the accompanying source code.

No Support for Tuples in Expression Trees

December 7th 2018 C# .NET .NET Framework EF Core

Tuples, as added to C# 7, can be a nice alternative to anonymous types in LINQ when you only want to return a subset of values from the queried type. Before tuples, this was only possible by creating an anonymous type in the Select method. Now you can create a tuple instead. However, if you try to do that with EF Core, the code won't compile. How come?

Offline Installation of .NET 3.5 in Windows 10

February 3rd 2017 .NET Framework Windows

Windows 10 by default doesn't come with .NET Framework 3.5 installed, however some older applications still require it. You can install it by enabling the corresponding Windows feature, however you need to be online for this to work. Fortunately you can use DISM.exe to work around that requirement.

Advent of Code 2016

For the second year in a row, I spent a significant amount of time in December solving the Advent of Code programming puzzles. Before writing the first line of code, I created a repository for my solutions. Unlike last year, I wanted to have all the code readily available for future reference. More than once, I actually looked up previous solutions while solving a more recent puzzle.

Strings in .NET Are Not Null Terminated

February 7th 2016 C# .NET Framework

Are you used to the fact that strings are null-terminated? Well, in .NET framework they are not. In this article I explore the consequences of that, explain the circumstances under which you might stumble across it, and suggest, how to avoid being affected by it.

Be Careful When Copying Visual Studio Projects

December 5th 2015 Visual Studio .NET Framework

You might not be aware of it, but Visual Studio projects have additional identity beyond their project file name and path. Each one of them contains a GUID value which should by definition be unique in normal circumstances. The troubles begin, when you create a copy of a project by copying its folder and renaming the files.

Book Review: Learning .NET High-Performance Programming

September 5th 2015 .NET Framework Book Review

I was expecting in-depth content, describing the good and bad practices in different scenarios supported by measurements, pitfalls to be aware of, options to consider. Instead I only got a high-level overview of several performance related aspects, at best.

Assembly Binding Log Causing Slow Assembly Loading

May 24th 2015 .NET Framework Debugging

Recently I was involved in troubleshooting a strange performance issue, manifesting itself in the form of long initialization time of each newly created process or AppDomain on one of the servers. In the end it turned out, it was caused by assembly binding log being enabled on that machine for a long time.

Using WinDbg for the First Time

When an application starts misbehaving in production, attaching a debugger to alive process is out of the question. Creating a memory dump and analyzing it in WinDbg is the way to go. Most of us are required to do this on rare occasions only. To make it easier for me in the time of crisis, I created a short cheat sheet.

Book Review: Learning NServiceBus Sagas

The content is not focused only on sagas at all. The samples are very contrived and almost impossible to make sense of by just reading the book. Not even the basic functionality and structure of sagas is properly explained, much less any advanced concepts and usage scenarios. I can't really recommend the title to anyone.

Book Review: Learning NServiceBus - Second Edition

Whether you're starting to learn about NServiceBus, considering the adoption of distributed architecture in a .NET framework based project, or just want to know what NServiceBus is about, you should read this book.

Minimizing Reflection Usage with Generics and Dynamic

September 15th 2014 Reflection .NET Framework

It's always best to completely avoid using reflection, but unfortunately that's not always possible. Sometimes you need to use APIs, which are not strongly typed. In such cases you should transition from reflection to strongly typed code as soon as possible: because of performance, and because of code readability as well. In this blog post I'll describe a couple of techniques which are useful in situations like this.

Install .NET Windows Service with a Different Name

Creating a Windows service in .NET could hardly be any easier. Installing multiple instances of such a service on a single computer is not that easy. Since there's not much documentation about it, many articles are describing over-complicated custom solutions instead of taking advantage of the APIs that are already available.

Strong Name Validation Failed Security Exception

May 2nd 2014 .NET Framework

A couple of days ago I encountered a surprising FileLoadException. The key to the solution was in carefully reading the complete exception message. The last sentence made it clear that strong name validation had failed.

Ready to Use Dictionary for Objects of Different Types

March 31st 2014 .NET Framework

Recently a colleague of mine mentioned that he has just learned about KeyedByTypeCollection, although it has been included with .NET framework since .NET 3.0. I'm writing this post, because I didn't know about it until that day, either. This leads me to believe that there must be many more developers out there who aren't aware of this niche class being readily available.

Using NDepend to Analyze Your Code

Recently I got my hands on the full version of NDepend and I decided to take advantage of that by trying it out on a couple of projects I am working on, both personally and professionally. It turned out that NDepend isn't all that easy to use if you want to make the most out of it. In this post I'll go over the steps I made to set everything up and reconfigure it in a way that made the results more meaningful to me.

Book Review: .NET 4.5 Parallel Extensions Cookbook

I have learned quite a few new tricks while reading the book and I would have even more if it wasn't for my previous hands-on experience with many of the topics covered. If you are considering or already developing parallel or asynchronous code, I strongly recommend reading this book.

Inconsistent Behavior of String Methods for Special Unicode Characters

August 19th 2013 Unicode .NET Framework

It seems that different String methods handle special 0xFFFD Unicode replacement character in different ways.

NAnt 0.92 Issues Building .NET 2.0 Projects on x64 Windows

August 12th 2013 NAnt .NET Framework

It's more than a year since NAnt 0.92 has been released, but if you take a look at the project issues page, many of them still report problems related to finding different versions of SDKs.

Book Review: Microsoft .NET Framework 4.5 Quickstart Cookbook

July 29th 2013 .NET Framework Review Book

The author really managed to convey a lot of information in a concise and useful way, although not all of the topics are covered equally well: some really do shine, while others could still be improved.

Wrapping Other Asynchronous Patterns in Awaitable Tasks

July 22nd 2013 Async .NET Framework

Writing asynchronous code in .NET framework 4.5 is pure joy thanks to task-based asynchronous pattern (TAP) and the async/await syntactic sugar. Although many APIs have been updated since the introduction of TAP to provide task based asynchronous methods which can be used with async and await, occasionally you will still encounter operations in APM (Asynchronous programming model) or EAP (Event-based asynchronous pattern) without a TAP equivalent. Fortunately .NET framework provides helpers which will make wrapping older style asynchronous operations into tasks much easier.

Book Review: Visual Studio 2012 and .NET 4.5 Expert Development Cookbook

The book addresses a lot of advanced topics throughout the chapters, as expected based on the target audience of experienced .NET developers. Still, most of the chapters include some basic topics as well, which slow down the pace.

BindingList Collection Is Read-Only

June 17th 2013 Binding .NET Framework

When you pass an instance of IList<T> to the constructor, the BindingList<T> doesn't create its copy. It serves as a wrapper for it, supporting only the operations also supported by the underlying collection.

Inconsistent Exceptions for WinRT File Operations

Recently I encountered strange and inconsistent behavior in exceptions being thrown by different file operations in WinRT.

Calling Task-based Asynchronous Methods from Class Constructors

Task-based asynchronous pattern has many advantages over other asynchronous patterns introduced in the past, most of them boiling down to the fact that it's really easy to get into and start using it. Like any other technology, it does have its pitfalls and there are many details to know about once you get into more advanced scenarios.

Book Review: .NET Framework 4.5 Expert Programming Cookbook

March 23rd 2013 .NET Framework Review Book

The book seems more like a collection of blog posts, which have passed a much stricter review process. If enough of them are of interest to the reader they should provide enough value to be worth the purchase. Check the table of contents online, before buying it.

Presentation on Reusing Existing Code in Metro Applications at Bleeding Edge 2011

This year's Bleeding Edge conference was taking place this week in the beautiful surroundings of Gozd Martuljek. The second day was dedicated to community driven redelivery of Build. As the last session of the day I had a talk on the aspects of reusing existing .NET framework code in Metro applications for Windows 8.

Call a Generic Extension Method Using Reflection

July 24th 2011 Reflection .NET Framework

Reflection is a great tool for calling methods on objects when their types are not known at compile time. Unfortunately the Type.GetMethod method doesn't work with generic methods, therefore we need to find the right method by iterating through all the methods returned by Type.GetMethods. Searching for alternatives I stumbled upon a solution using expression trees. It got me wondering though, which of the two solutions actually performs better.

XmlSerializer Constructor Performance Issues

June 12th 2011 Serialization .NET Framework

XmlSerializer is often a great choice for persisting objects or transmitting them over the wire, either by using default object serialization tailored only with attributes or by implementing the IXmlSerializable yourself. If you're not careful though, this might come at a significant performance cost.

Value-Type Parameters in Reflection

March 23rd 2011 Reflection .NET Framework

It seems that no matter how much experience one has with .NET framework, there are still surprises awaiting him somewhere down the road. This time I'd like to point out an interesting behavior of MethodInfo.Invoke many of you might not be aware of. I certainly wasn't, until today.

Code Access Security Strikes Back in .NET 4

March 4th 2011 .NET Framework

One of the changes in .NET Framework 4 was the retirement of Code Access Security (CAS). Until recently this was something, I have only read about at the time of release, but it didn't have any effect on my day to day work. Therefore I was even more surprised that an application which has recently been migrated from .NET 2.0 to .NET 4 suddenly failed to start from the network drive while working flawlessly from the local machine.

Unit Testing with NUnit in Visual C# 2010 Express

My favorite environment for running NUnitunit tests during the development process is definitely Unit Test Runner in CodeRush. When I just recently had to get a usable development environment up and running with Visual C# 2010 Express, I had to find a different solution since extensions are not supported in the Express SKUs of Visual Studio.

XML Serialization Issues or Having Fun with TimeSpan and XmlIgnore

November 10th 2010 Serialization .NET Framework

Recently I tackled a seemingly simple task: XML serialization of a generic class used with a TimeSpan data type. It turned out that XmlSerializer doesn't serialize the TimeSpan structure at all.

EventLogTraceListener Can Cause an Application to Crash

September 1st 2010 Event Log .NET Framework

Trace listeners are a great mechanism for troubleshooting and monitoring applications in production environment. What I didn't know until recently, is that by adding a trace listener to your application you can cause it to crash.

Programmatic Manipulation of Binary Excel (.xls) Files

A few months ago I worked on a small spare time project which included some manipulation of binary Excel (.xls) files. This seemingly simple task soon turned out to be quite a challenge if you want to handle it right. The post you are reading is a short summary of my experiences. They should make your choices easier if you are about to tackle a similar problem.

Setting Up SVN and CC.NET for .NET Development

Subversion and CruiseControl.NET can be invaluable tools in your .NET development process. There are many resources available to help you get started which I'll try to gather in this post along with some of my personal experiences.

Send E-Mail As and On Behalf Of

Microsoft Exchange supports Send As and Send On Behalf Of permissions to be granted to users for individual e-mail addresses. Sending e-mail from Outlook for these users is very simple. If you want to achieve this from code there is a little more work involved.

Old ActiveX Controls Under .NET 2.0 SP1

April 29th 2008 .NET Framework Native Interop

.NET Framework 2.0 Service Pack 1 caused the C# compiler in Visual Studio 2005 and later to set the NXCOMPAT bit for all build targets without an option to turn this new behavior off. This means that DEP (data execution prevention) will kick in unless it is turned off completely in the operating system.

Always Close DeflateStream Before Reading Results

November 24th 2007 .NET Framework

Close() must be called on a CompressionStream before you start reading from the underlying stream. Calling only Flush() is not enough in this case.

Notes about RSACryptoServiceProvider

November 24th 2007 PKI .NET Framework

In my opinion RSACryptoServiceProvider class is seriously under-documented in MSDN. For future reference I'm listing the solution to two problems I had.

OCR with Microsoft Office Document Imaging

If you need cheap and simple OCR functionality Microsoft Office Document Imaging Type Library (MODI) is a nice option if its requirements (Microsoft Office 2003 or later) and limitations (limited language support) don't bother you.

MCP Exam 70-536 Experiences

December 25th 2006 .NET Framework Certification

I've recently passed the MCP exam 70-536: TS: Microsoft .NET Framework 2.0 – Application Development Foundation. I found the exam quite easy with only a few really nitpicking questions.

Configuration.Save Requires Full Control Access to a File

September 19th 2006 .NET Framework

Don't use Configuration.Save in scenarios where users might only have read and write permissions for the configuration file.

Last Modification Time of a Web Page

September 7th 2006 HTTP .NET Framework

The following code returns the time when a web resource was last modified. Maybe it will be useful to someone.

Writing to EventLog

June 9th 2006 Event Log .NET Framework

Before using EventLog.WriteEntry for adding events to event log you should consider calling EventLog.CreateEventSource to make your application a valid source of events. Keep in mind though that you need administrative privileges for it to succeed, therefore it is best to call it at installation time.

Implementing Plugins with Late Binding

June 4th 2006 Reflection .NET Framework

Essentially everything you need to implement plugins in your application is some way to dynamically instantiate classes at runtime. In COM world this was achieved by calling the CreateObject function. In the managed world you should use AppDomain.CreateInstanceAndUnwrap.

Marshalling System.String to char* and Vice-Versa

By switching from C# with P/Invoke calls to Managed C++ when implementing a managed wrapper for the ANSI C style library I stumbled upon, I wanted to avoid the tedious and error-prone task of writing the P/Invoke signatures for function calls and user-defined types for the structures they used. As a side result I also managed to avoid most of the advanced marshaling issues with complex data structures.

Implementing a Managed Interface in C++

Managed C++ is actually quite nice in the 2005 version. You probably still wouldn't want to use it if you could get away with C# or VB. But if platform invoke is giving you too many headaches, you might want to take a look at it.

Use Stopwatch to Measure Code Execution Time

February 28th 2006 .NET Framework

To measure the time it takes to execute a piece of code before .NET 2.0, you had to develop your own high resolution timer by wrapping the unmanaged calls. Stopwatch class implements the same high resolution timer functionality out of the box.

Static Class Constructors Should Never Throw an Exception

February 23rd 2006 C# .NET Framework

No matter what you're doing in the static constructor, never allow it to throw an exception unless the problem is indeed fatal and you intend to quit the program immediately. In all other cases provide reasonable defaults and handle changed circumstances elsewhere in the code.