Dustin Horne

Developing for fun...

Generic Attributes in C#

First I'd like to note a correction as this original post was unintentionally misleading.  The following works with Mono but will not work with the full fledged .NET Framework.

This afternoon while doing some related research I realized that I had been doing something for awhile that appears to be somewhat of a unicorn in the C# community:  using generic attributes.  Upon further research I saw a lot of information on creating generic attributes that ranged from "you can't" to "here's how you create a custom type descriptor and dynamically inject the attribute".  As I have been doing it for awhile a much easier way, I somehow was never aware that it was a problem for some, so here is how you do it.

More...

Json .NET for Unity Developers

I wanted to kick off my category on Unity (sometimes called Unity3D, though Unity is the proper name) by talking about Serialization, especially in conjunction with Json .NET (the Newtonsoft library) which I've ported to Unity 3.5+ and made to be compatible with iOS and the Web Player.  I'll give examples of serialization and deserialization with both Json and Bson (Binary Json).

More...

Goodbye XNA, Hello Unity

Before writing about Unity, I wanted to provide clarification for my subscribers and let them know that I've moved away from XNA development and moved to Unity.  While XNA isn't entirely dead (there are still plenty of XNA developers around and still using XNA for desktop and XBLIG games), it is certainly fading away. 

More...

Sending Email With Google Mail and ASP.NET

If you're using Google Apps for your email you may want to send email through a Google Apps account from your website.  This is a process I've found to be poorly documented (the documentation can be difficult to find) and there are several examples of different implementations, some of which work and some do not.  You need to make sure you're using the correct outbound server, the correct port, and setting up the authentication credentials properly.  Here I'm going to show you how to make it work. More...

Identity Crisis - Identity vs SCOPE_IDENTITY In Sql Server

A common need when writing insert queries is to return the last Id that was generated when inserting your record.  There is more than one way to retrieve this value and it can come back to bite you if you're not careful.  In simple applications it's fine and simple to just append Select @@Identity to the end of your query.  If you manage the database and know the structure will never change this isn't a problem.  In larger scale applications, a DBA can make a simple change that can have major implications.  I'm going to demonstrate the problem and show you how to avoid this pitfall. More...

Simple Asset Manager for MVC

Lately I've been using a lot of jQuery and other custom javascript in my projects.  I like to use external CDNs when possible to load my script files.  In particular, I like to use the asp.net CDN for use with jQuery.  For much of this work I can simply put my script references in the layout pages, however there are times when I want specific scripts for specific pages.  There are also times when I want to be able to upgrade a script to a newer version.  This may require modifying multiple views.  Additionally, it would require modifying my HTML/Razor for at least my layout view and re-uploading it to the server. More...

AJAX File Uploads with jQuery and MVC 3

Recently I was working on a project that required upload of images.  I wanted to upload the images AJAX style without refreshing the page and thought jQuery would be a good fit.  Using jQuery to post standard forms is extremely simple, but when posting multi-part forms for uploading files it's not so intuitive.  This is due to browser security restrictions and sandboxing.  Today I'm going to show you how to fake an asynchronous upload without reloading the page and get a result back from the server. More...

Dynamic Custom Error Pages in ASP.NET MVC 2

Recently, I had to implement a dynamic custom 404 error page in an ASP.NET MVC2 website.  My first instinct was to turn CustomErrors mode on and setup a 404 Error, but this failed to return my custom error page in a shared hosting environment and instead displayed the default IIS 404 page.  I'll walk you through fixing this in just a minute, but for now I want to show you how to create the custom 404 page. More...