Tag: C#

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...

The OutputPath property is not set for project

I recently got the error “The OutputPath property is not set for project ‘[ProjectName]’. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration=’Debug’ Platform=’BPC’. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or...

Including Exception Details in WCF (IncludeExceptionDetailInFaults)

Sometimes when you receive an exception when debugging a WCF service, you receive the following message : The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn...

Quick Formatting Tips in Visual Studio 2010

Formatting code not only keeps OCD programmers like me sane being organized, it also helps with the readability of your code when ever you or somebody else views it for maintenance. However sometimes formatting the code quickly in Visual Studio 2010 is not exactly straight forward so I thought I’d give a few tips from what I learned so far,...

%d bloggers like this: