Category: C#

Filter an ObservableCollection with a CollectionView in C#

Using an ObservableCollection and need to filter its contents? A quick and easy way I found was to create and bind to a CollectionView to perform the filtering for you. Step 1 : Create the Observable Collection The first step is to create the observable collection. This will work for objects or system type lists, so feel free to use...

Saving and Loading a Byte Array To File in C#

Need a quick way to save a byte array to file and read back? So did I, and thought I’d include this simple code snippet for anybody who needed it as well. Includes Code : Saving to File Note below, there are two additional options (besides the name) you can include in the FileStream, FileMode and FileAccess. FileMode lets you...

The Difference Between Decimal, Double, and Float (Examples in C#)

The Decimal, Double, and Float variable types are very similar in the fact that they use a decimal in their value (Actually called the Radix Point), but are different in the way they store that value (Amount of bits reserved for the mantissa and exponent), and should be used in specific situations versus interchangeable. The main difference is Floats(Single) and Doubles...

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

I don’t know how many times when I was debugging my application which had two databases communicating, I got the following error : Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. This basically means something updated the row since the last...

Unable to update the EntitySet ” because it has a DefiningQuery and no InsertFunction

I was deploying a build on a cloud test machine with its own SQL Server and data. I was testing a sync function (a mobile handheld grabbing information from a server) and got the following error. Unable to update the EntitySet ” because it has a DefiningQuery and no element exists in the element to support the current operation. What...

ReflectionTypeLoadException : Could not load file or assembly ‘[DLL Name]’ or one of its dependencies

Getting a Reflection Type Load Exception, and confused by the message or simply can’t figure out what the issue is? As Microsoft defines the exception as, “The exception that is thrown by the Module.GetTypes method if any of the classes in a module cannot be loaded…” which is pretty broad. After debugging a few different types of this exception, I’d thought I’d...

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Have you ever assigned a value to an IEnumerable from a database, then try to access in a foreach or something similar and get the following? “ObjectDisposedException was unhandled by user code : The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.” If you are using a using statement with your entity context,...

When to use Parse, Convert, and TryParse in C#

When converting values in C#, we are given three options : Parse, Convert, and TryParse. My suggestion would be to use which method based on where the conversion is taking place. If you are validating user input, an int parse or a convert will allow you to give specific error messages. If you are merely converting in a more discreet...

Using Transactions in the Entity Framework (EF4)

You have multiple updates and want to implement transactions into your database updates in the Entity Framework? I had to do just that in C# , so I thought I’d share what I learn for to remember, and for you to learn. To do this, we must create a TransactionScope, and move around our save function a little bit in...

The breakpoint will not currently be hit. The source code is different from the orginal version.

I noticed that my code was not being reflected in the current build of my application. Then taking a closer look and setting a break point at the code that was not being ran, I hit F5 and noticed a bubble with a warning triangle that had the following message. The breakpoint will not currently be hit. The source code...

Error While Sending a Class Collection Over a WCF Service

I had spent a great while debugging an operation which returned a collection an entity object. However, I had a bug in my code and I could not find what was causing it. I was given the following message over, and over, and over. The socket connection was aborted. This could be caused by an error processing your message or...

%d bloggers like this: