You’ve been there too. A month ago you wrapped up your first release. You were happy and went for a beer with your workmates. The next month things didn’t go so well. As you start integration testing again, you realize something has gone wrong. You dig down, and discover your app had serialized some useful data to disk not so long ago. Yet, as the new version does its thing, it crashes with a vengeance, when it tries to get that data back from the same place. As you sigh, and realize there won’t be any beer that night, you notice that those serialized bits of data have changed schema between deployments. You think – I do want the app to re-use that data without breaking… So how on Earth do I get around this?

The Partition Problem is a very old conundrum in Computer Science. The usual question goes: given some buckets of some capacity, and some items of some size, how can I distribute the items by the buckets in an optimal manner?

The answer to this is more complex than it seems at first glance, as it depends on what you mean by some buckets and optimal.

TLDR;

You get a NullReferenceException when your code is trying to use a null variable. You’re either calling a method on that variable or accessing a property or something else.

The problem is that there’s nothing to call upon to begin with. Either you have never assigned anything to that variable or you have set it to null yourself before trying to use it. Or some external code is returning a null to you, which you are not validating before you using it.