Friday, December 2, 2011

Extension Methods: Straight to the Point!

I kept looking at many articles on extension methods and for some reason I couldn't get mine to work. It then dawned on me that the class where you declare you extension methods MUST BE STATIC. That is a gotcha and for some reason it isn't emphasized even though all of the examples clearly have static classes and methods.

The basics of extension methods are:

  1. Static Class
  2. Static Methods
  3. Use the "this" keyword to in order to infer what is expected to use the extension method

//Basic example
public static class CustomExtentionMethodsClass
    public static void IncrementAllByNumber(this List list, int intValue)
        for(int i; i < list.Count; i++)
            list[i] += intValue;

List lstOfInt = new List();



//Elements should all be incremented by 2

Thursday, November 10, 2011

C# String PadLeft() and PadRight()

This has been an irritating method to use especially when you don't use it too often. Here are some tips about using PadLeft() and PadRight().

First off it is not a static method, you need an instance of a string in order to use it.
Secondly keep in mind that these methods are poorly named, they don't actually pad anything unless you specify how much you want to pad plus the size of the current string that you want to pad. I think that is rather stupid. No really, what is the point of that method if it doesn't implicitly use the size of the current string? I must be missing something.

Usage if you are trying to actually place spaces next to (either side) of the string in question

string strTarget = "content";

strTarget.PadLeft(strTarget.Length + 7);  //Result: "       content" 
strTarget.PadRight(strTarget.Length + 7); //Result: "content       "

If you didn't specify the string's length then you would not see any padding. This is an irritating gotcha.

Sunday, September 11, 2011

Remoting Servers 101

Before I jump into this, I just want to explain that Remoting is an old .Net v1.1 technology and it is no longer supported. However it still gets the job done if that is what you are using already or if you need a really old code to talk to a really new code and you are not at liberty to use WCF. The following example I am going to provide shows .Net v2.0 talking to .Net v4.0. If you have the opportunity to design something from scratch with the time to learn how to do it correctly; please use WCF instead of Remoting. There is no point in using old coding if you can use the new stuff.

Introduction to Remoting
In this example you need to understand that there are two parts to Remoting always, there is the Client or Consumer and the Proxy or Remoting Server. Remoting is great for exposing parts of a dll to an older .Net version or to avoid dll hell in a sense. You can have a centralized location for your main or base dll and just have other components point to it. The benefit here is to not have to make sure that all locations have an exact copy of the latest dll (hence the mention of dll hell).

Remoting Anatomy
There are some basic parts that are involved in remoting and keep in mind a lot of these same concepts are now used in WCF. Remoting requires the following to work:

  1. You must use Remoting locally, it will not work across the net and it isn't safe to attempt it either. Not to mention that it would kill performance.
  2. You must have an Interface Library and that library must be identical for the client and the proxy.
  3. You must have a Remoting Project (you could probably get away without having it, but for simplicity's sake just have one).
  4. You must be able to host these projects in IIS. I have done this with IIS 5, 6 and 7. Trying to use casini in this case is just a pain in the ass, just use IIS.
Here is a picture of the projects I am used to using and seeing when I work with remoting:
Project Descriptions:
  1. BaseWebApp - ASP.NET v4.0 - This is the application or dll we want to expose. Please be aware that Session and other web related objects are not completely available during remoting access. This application is oblivious to the fact that the Remoting Server exists (kind of). Think of the Remoting Server as a parasite and the BaseWebApp as the host. You are going to need to put the RemotingServer and RSInterfaceLibrary into the BaseWebApp's bin folder, this will be explained more later.
  2. PublicWebService - ASP.NET v2.0 - This is the client project that will be consuming the remoting server or utilizing it in order to use the exposed dll. Notice that it is in an older .Net version and would not be able to use the target dll as a reference even if we wanted to. Unless you down graded, which is not suggested or good design.
  3. RemotingServer - ASP.NET v4.0 - This remoting server project will do all of the accessing of the target dll that we are exposing, hence being called the proxy. It is a proxy between the consumer and the exposed dll. This is necessary because we don't want to just allow the web service to have access to everything, only what is allowed by the remoting server.
  4. RSInterfaceLibrary - ASP.NET v2.0 - This remoting server interface library is .Net v2.0 because it can be used by the RemotingServer and the PublicWebService. I did this for simplicity, but if this cannot be done, such as using a .Net v1.1 web service, then you will have to make an exact duplicate of this interface in both flavors of .Net and maintain two separate projects. It sucks, but sometimes if you don't have a choice due to poor code management or a lack of manager foresight you might be stuck in this predicament. One thing to keep in mind is since you are using an older version of .Net for the Interface Library it is important to keep backwards compatibility in mind. So in other words, if you are maintaining a .Net v1.1 interface library and a .Net v4.0 interface library; then it is safer to make your changes in .Net v1.1 and port them over to .Net v4.0. Do NOT go backwards because it can cause very difficult to troubleshoot problems. Just don't do it.
So to recapitulate, the right way to think about this is to think about these projects in pairs... kind of. Lets have two groups:
  • Group A - PublicWebService and RSInterfaceLibrary. Consumer/Client. 
  • Group B - BaseWebApp, RemotingServer and RSInterfaceLibrary. Remoting Server/ Proxy.
Groups A and B speak to each other via the RemotingServer, but must have the RSInterfaceLibrary in common because it is their Contract with each other. This is an implicit concept in Remoting. For WCF it is an explicit concept now, which helps in my opinion. I can't say this enough, MAKE SURE THE INTERFACE LIBRARIES ARE IDENTICAL!

On to the Code. How does this all work?
I like to think of all this as creating pipelines, because essentially that is what this all is. You are creating a tunnel from point A to point B or rather from Group A to Group B. Follow these steps:
  1. Create the BaseWebApp web application project which is in ASP.NET v4.0
  2. Create the PublicWebService web service project which is in ASP.NET v2.0 (or could be .Net v1.1, what ever you require).
  3. Create the RemotingServer class library which is in ASP.NET v4.0
  4. Create the RSInterfaceLibrary class library which is in ASP.NET v2.0. You only need to create one of these projects because .Net v4.0 can take .Net v2.0 as a reference with no problem. If you needed to create one as .Net v1.1, then make two of these projects, one in .Net v1.1 and one in .Net v4.0. You will then have to have two version of visual studio open, which is not a problem, but a little more complicated.
Code Snippets

  1. Create a new folder called "BusinessObjects"
  2. Add a new class to it called "BaseObject.cs"
  3. Include the following code:
    public static string UsefulData()
        return "BaseWebApp.BusinessObjects.UsefulData() : " + DateTime.Now.ToString();
  4. Host this project in IIS using the same name as the project.

I like returning the current time because it is something that is constantly updating without me having to do it myself and it lets you know if something is working right now.

  1. Take the stock class and rename it to "InterfaceLibrary.cs" (for this example I am not using the proper naming convention of IClassName to be more clear)
  2. Use the following code:
public interface InterfaceLibrary
    string GetUsefulData();

  1. Take the stock class and rename it to "Gateway.cs"
  2. Make a project reference or dll reference to the "BaseWebApp.dll"
  3. Make a project reference to the "RSInterfaceLibraray" project
  4. Open "Gateway.cs" and replace the code with this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseWebApp.BusinessObjects;

namespace RemotingServer
    public class Gateway : MarshalByRefObject, RSInterfaceLibrary.InterfaceLibrary
        public string GetUsefulData()
            return BaseObject.UsefulData();

  1. Make a project reference to the "RSInterfaceLibraray" project
  2. Add a class called "RemotingLogic.cs"
  3. Add the following code to this class:
    public static InterfaceLibrary GetProxyObject()
        string strURL = System.Configuration.ConfigurationManager.AppSettings["remotingServerURL"];
        return (InterfaceLibrary)Activator.GetObject(typeof(InterfaceLibrary), strURL);
  4. Add the following code to the "Service1.asmx.cs" code behind:
    public string GetUsefulInfoViaRemoting()
        InterfaceLibrary proxy = RemotingLogic.GetProxyObject();
        return proxy.GetUsefulData();
  5. Host this web service in IIS using what ever name you want.
Configuration Files

  • Client or Consumer Side - You can use this configuration in any kind of consumer that I know of. Web.Config or App.Config. Here is the configuration value for the Web Service side:

    This indicates the direction or location of the remoting server. If you navigate to it you will get an HTTP 500 error, so don't bother it doesn't work that way.
  • Proxy or Remoting Server Side - I have only ever used this configuration with a web application, I don't know what else this could be used with.

    This is what exposes the remoting server on the web application. It piggy backs off of it, like a parasite on its host.
After implementing all of the above, make sure to compile everything and most importantly for the BaseWebApp and the RemotingServer you need to move the "RemotingServer.dll" and "RSInterfaceLibrary.dll" to the BaseWebApp's bin folder. If you did everything right then this should work right off the bat.

One of the most confusing parts about the configuration is the Web Application's side. Here is the explanation:

I got this information from here:

There is ton's more that can be done with this stuff. I recommend that if you are going to have multiple remoting servers for the same application don't bother creating multiple projects, you can just use the same projects and just make sure to configure them properly. Here is an example:


This indicates that you have two additional classes "Gateway2.cs" in the remoting server project and "InterfaceLibrary2.cs" in the interface library project. I used the number 2 just to indicate that it is a second pipeline, but you can call it what ever you want.


Friday, September 9, 2011

Adventures In Web Service and Remoting Server Craziness

I don't think there are that many people out there that still have to deal with more than one .Net Framework, but I have to deal with 3 simultaneously constantly. That means I use 3 different versions of Visual Studio simultaneously. The best part is everything I have to deal with has to talk to each other.

On to the topic at hand though. I learned a valuable and obscure lesson about getting a Remoting Server that is written in .Net v4.0 to send a custom object to a Web Service written in .Net v1.1.

All of the finer details aside here is the lesson I learned. If you are going to make a higher version of .Net - anything greater than v1.1 - then you need to make sure that you write the class in .Net v1.1. I am not referring to unsupported objects or technology such as Linq, I am referring to unsupported structure.

So for example if you get an error like so:
"...<PropertyName> k__backingfield were not found."

There is a good possibility that you might have tried to use a structure that isn't backwards compatible with .Net v1.1 and here is an example why:

//.Net v4.0 Side
public class SerializableTestObject
    public SerializableTestObject()

    public bool BoolField { get; set; }
    public bool StringField { get; }

//.Net v1.1 Side
public class SerializableTestObject
    public SerializableTestObject()

    private bool _boolField;
    public bool BoolField { get {return _boolField; } set { _boolField = value; } }
    private string _stringField;
    public bool StringField { get { return _stringField; } }

Even though those classes are technically identical, the difference is that .Net v1.1 doesn't understand what get; or set; means. That was introduced in .Net v3.0, so you will get the weird error described above if you try to pass the .Net v4.0 class version to the .Net v1.1 class version.

Thursday, September 8, 2011

Remoting Server Troubleshooting

If you are having trouble with getting remoting to function properly and you know you have everything configured properly then it is more than likely caused by a bad or incomplete dll. Here is a list of things to try before giving up on trying to get this to work.
1. Remoting errors are never helpful and usually will be a 500 Internal Server Error:

This will occur when the proxy object attempts to access the remoting server and fails. Literally what happens is an error occurs on the remoting side (proxy side) and instead of return something useful it will return the following block of text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>500 - Internal server error.</title> <style type="text/css"> <!-- body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} fieldset{padding:0 15px 10px 15px;} h1{font-size:2.4em;margin:0;color:#FFF;} h2{font-size:1.7em;margin:0;color:#CC0000;} h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; background-color:#555555;} #content{margin:0 0 0 2%;position:relative;} .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} --> </style> </head> <body> <div id="header"><h1>Server Error</h1></div> <div id="content"> <div class="content-container"><fieldset> <h2>500 - Internal server error.</h2> <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3> </fieldset></div> </div> </body> </html>
This block of text is the html of the image directly above. The one thing to keep in mind is if you see this, then you need to make sure that everything is configured properly first, make sure the remoting URL is correct. Pay attention to the errors returned though because sometimes they are not the 500 error. If it is a 404 error then you know that the URL you provided was wrong. If the configuration is fine then go through the steps listed below.
2. Manually delete all dlls and recompile everything. You must make sure to move your base project dll to the remoting project’s bin folder. After successfully recompiling the remoting server dll (and respective interface library), should you move the remoting dlls to the base project’s bin folder. No part of this exercise should fail. Make it a habit to periodically move the base project dll to the remoting project’s bin folder to give it an update copy to work with. That is where the remoting server gets its meta-data from.
3. Make sure that the interface library looks exactly the same on the consumer side and the remoting side (proxy side). If the interface differs at all, then you will have failures.
4. Sometimes, during debug, .Net can get all mucked up with bad cache and you will see a message like this:

In the path that is provided in the picture you can see the directory name, this directory name is the same name as the virtual directory used in IIS. This is where all of the cached information for the web application is stored. The problem with this picture is I was getting this error when I was running a different virtual directory which has nothing to do with that other virtual directory. The solution here is to reset IIS by running the following command at cmd:
iisreset /restart
If you continue to have this problem then you should do the following:
a.       Stop IIS via cmd: iisreset /stop
b.      Open up the affected path, in this case open: “C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\”
c.       Locate the virtual directory that is giving you trouble and delete it. This is safe to do because it will just be re-cached when you run the application again.
d.      Start IIS via cmd: iisreset /start
e.      Run your application to re-cache it. This could take longer than usual so be patient.
This error message can also appear if you are trying to attach to a process with an old debug file. The way to fix that is to simply rebuild your files and make sure you are in debug mode. If you attempt this during release mode you will get this error message too.

Thursday, September 1, 2011

SQL Server: Tips on Declaring a Decimal Data Type

One of my pet peeves about SQL Server is the decimal data type. Declaring it once in a table where you don't have to do any math on it is normally okay, but I get very confused when I have to take two unknown values, do a mathematical operation on them and then store them into a table on the fly. This usually generates that oh so annoying: "Arithmetic overflow error converting [type] to data type numeric."
Here is an example:

CREATE TABLE tblDecimalTest
    DecimalColumn dec(5,2) NOT NULL

INSERT INTO tblDecimalTest ( DecimalColumn ) VALUES(1.1);     -- OK
INSERT INTO tblDecimalTest ( DecimalColumn ) VALUES(5);       -- OK 
INSERT INTO tblDecimalTest ( DecimalColumn ) VALUES(5.1234);  -- OK
INSERT INTO tblDecimalTest ( DecimalColumn ) VALUES(99999);   -- Int Conversion Exception
INSERT INTO tblDecimalTest ( DecimalColumn ) VALUES(99999.0); -- Numeric Conversion Exception

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)
Msg 8115, Level 16, State 8, Line 4
Arithmetic overflow error converting int to data type numeric.

The statement has been terminated.
Msg 8115, Level 16, State 8, Line 5
Arithmetic overflow error converting numeric to data type numeric.

The statement has been terminated.

I found a trick to sort of avoid this kind of problem, it won't always work if you are going to use it to preset precision, but it is a start to something better than just randomly deciding or trying to estimate the amount of precision that you will require. Take your inputs, typically a query, and store the virtual table into a new table. After the table is created highlight its name and press Alt + F1, this will give you the complete listing of a lot of information about the table that was just created. Most interestingly and most valuable it will tell you the dimensions of the decimal column that it has appropriated for you.
Example 2:

--This is just an example, it is taking all of the rows from the previous example and multiplying them by 20
	decUnknownSize = DecimalColumn*20
INTO tblDecimalTest2 --Create a new table and NOT a temporary table because the trick won't work with a temp table
FROM tblDecimalTest;

Screen Shot of Alt + F1

As we can see in the screen shot above the precision has been determined for us which helps you if you need to manually create the table for what ever reason. There is only one draw back to this scenario, this will only work if you know that the values you are working with will never be bigger than what has been specified already. Otherwise you are going to find yourself fudging with the numbers a lot, in which case you might be better off "SELECT INTO" a real temporary table (#/##) or a Common Table Expression because it will be created for you on the fly. This won't work if you are declaring the schema of a table, temporary table or a table variable.

MSDN Link for Decimal and Numeric Data Type

Sunday, August 7, 2011

Blog Title

I changed the title of my blog because I am going to encompass all topics that have baffled me or confused me. I haven't gotten around to it yet, but I am going to post about an irrigation system that I had a lot of trouble with. I want to construct it with photographs and make it very legible and easy to understand. I couldn't find ANY help online with my problem, so I am going to make an effort to fix that problem.

Monday, August 1, 2011

HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid. Error Code: 0x8007000d

This is probably one of the more annoying errors I have ever encountered with IIS7. All the information I was finding for it online was very vague and my symptoms were very different from everyone else's. So here are some tips I have on it:

The first thing to test is if you can run a basic html (*.htm) page. Create an html page with the *.htm extension and put some basic text in the file for recognition. Browse to the file, if you get this error even when trying to run a basic html page then you have a bigger problem.

This problem is more than likely caused by the web.config, in order to verify this claim temporarily remove or rename the web.config. You can rename it to web.config.bak temporarily. Browse to the html file you created earlier, if you can browse to it okay then it is your web.config that is causing the issue. Try replacing it, if the issue persists then it is not necessarily the schema causing the problem. It could be something in your web.config that IIS doesn't recognize because a module is missing from IIS.

The final solution found for my particular case on was to simply remove a section out of the web.config that was the root cause of the error. There was a section that looked like this:


Where the node "<otherstuff />" can be ignored, it is literally other stuff that is normal to find in that section, so ignore it.

In order for this rewrite rule to work the rewrite module MUST be installed in IIS and since it wasn’t I was getting this error. The distinction for the error I was getting was that “Config Error” and “Physical Path” were both blank which was not helpful at all. I will try to get a picture of what I am talking about.

Some Helpful Links:

Friday, July 29, 2011

How to Iterate Through all Enums from a Class in C#

This took me a good while to figure out. This is specifically for looping through multiple enumerations declared inside of a class. This code would have to be modified slightly in order to loop through all enumerations inside of a namespace. I searched for this code everywhere on the net and I couldn't find it so I wrote it myself.


public void GetAllEnums()
 object enumValue;
 string[] arrEnumNames;

 Type enumType;
 FieldInfo field;
 MemberInfo member;
 //Get all of the members of this class, this includes everything
 MemberInfo[] members = typeof(AllEnumsToTable).GetMembers();

 //Loop through the members.
 //Hard coded to 7 because I can't figure out how to filter just for enums
 //System.RuntimeType isn't allowed to be used for what ever reason
 for (int i = 0; i < members.Length; i++ )
  member = members[i];

  if (member.MemberType == MemberTypes.NestedType)
   enumType = Type.GetType(member.DeclaringType.FullName + "+" + member.Name);

   if (enumType.IsEnum)

    arrEnumNames = enumType.GetEnumNames();

    foreach (string name in arrEnumNames)
     field = enumType.GetField(name);

     enumValue = field.GetRawConstantValue();

     Console.WriteLine("Key {0} Value {1}", name, Convert.ToString(enumValue));


Wednesday, July 20, 2011

Tuesday, July 19, 2011

Cisco IP Communicator Virtual IP Phone Hijacks Port 80 When You Aren't Looking

I have reproduced this problem so it isn't a bunch of hooey or heresy. If you are using the "Cisco IP Communicator" Virtual IP Phone and you work with IIS on the same machine you could mistakenly run into a scenario where the Virtual IP Phone hijacks port 80. This is especially a big problem if this machine is hosting an application that people are trying to hit externally (as opposed to locally IE: http://localhost/)

How does this happen?
Follow these steps to recreate the problem (or just read through them):
  1. IIS Must be running first
  2. Hit your IIS Server externally (from another computer) via IP or Computer name to verify that IIS is functioning properly. IE: or http://ComputerName/
  3. Start Cisco IP Communicator
  4. Reset IIS - (cmd: iisreset /restart)
  5. Hit your IIS Server externally again, notice this time you are looking at a Cisco Page running off of Java?
What is most interesting about this is there is no Preference or option to turn this shit off (easily), it just happens. THANKS CISCO I APPRECIATE IT

OMG How do I make it stop!
The good news is you can make it stop and here are the steps on how to do that:
  1. Exit out of "Cisco IP Communicator" and I don't mean minimize, I mean close the program completely.
  2. Reset IIS
  3. Hit IIS externally again, you should see what ever it is you are hosting in IIS, congrats.
  4. Alternatively: You can just restart your computer, that should work too.
I hope Cisco has a way to avert this issue in the future. I think you have to edit the registry, but I am honestly not sure. I don't like the idea of this program hijacking my port 80, especially in the middle of development. I work with two machines because of our setup at work; otherwise I don't think I would have figured this out.


My setup, just for reference:
Windows 7
Visual Studio 2010

Friday, July 8, 2011

Windows 7: How to locate a task you created in the Task Scheduler

I created a task recently in the windows 7 task scheduler and I couldn't find my task after I created it. I saw other people were having problems with this too so I just wanted to point out one way to find your task again.

Open up the Task Scheduler (windows orb, search for task scheduler) and assuming your task is running look at the bottom of the window in the section named Active Tasks. Look through those tasks until you find the task you created.

If you need to edit your task
After locating your task double click on it. You can review it in the window show, but in order to actually edit it you need to click on the properties option located on the right hand side.

And there you have it, you have successfully located your task and you can modify it now.

If your task isn't running I am not sure now to locate it. I will try to figure that out later.

Sunday, June 26, 2011

Monetized my site

I monetized my site cause I am a poor bastard and maybe I can make a few cents, who knows. Wasn't really doing this to make money, but hell who knows what could happen in the future.

How to install sql server management studio 2008 component only

I posted an answer to this question on Stack Overflow here

Wednesday, June 22, 2011

Storing null in a Column will compile, but will cause run time exception

You can legally store a null in a column from a data row and the code will compile. Don't do this thought because it will definitely throw an exception during run time :)

dr["columnName"] = null; //This will throw an exception during run time

The remedy is to just use DBNull.Value:

dr["columnName"] = DBNull.Value; //This is legal

Friday, June 10, 2011


This is something that I don't do often, but it pops up every now and again. I always forget how to do it, so I have to look it up each time.

Here is an example:

UPDATE alias
 col1 = value,
 col2 = value,
 col3 = value
FROM table1 alias
 INNER JOIN table2 blah
  ON =
WHERE otherconditions

Thursday, June 9, 2011

Background goes white on post back

Have you ever been working on a web form or aspx page, then on post back the background color just turns white?

That is due to two different issues from what I have seen. One of which is if you have HTML tags that are not in the proper format or not closing in the right order.

For example:


If you have any of that going on, fix it immediately. It is wrong to begin with and just because HTML and things like it are usually dealt with very laxly doesn't mean it is okay to do it wrong. Every browser treats these kinds of mistakes differently.

The other problem that I have seen which is usually the main culprit is in the body tag. I don't know when this was okay to do, but it isn't supported anymore so it needs to be updated and stop doing it:

<body bottomMargin="0" bgColor="#ffffe0" leftMargin="0" topMargin="0" rightMargin="0" MS_POSITIONING="GridLayout">

The right way to do this is:

<body style="margin:0 0 0 0background-color:#ffffe0;">

This is a problem I keep running into while working on older sites etc...

Wednesday, June 8, 2011

++i vs. i++, YES they are different!

For this first test you will see that there isn't a difference, it is working differently, but you cannot tell the difference in this example:

public static void IncrementTest()
 for (int i = 0; i < 10; ++i)

 for (int i = 0; i < 10; i++)

This next example highlights the differences between i++ and ++i.

public static void IncrementTest2()
 int i = 0;
 Console.WriteLine("Initial Value: {0}\n", i);
 Console.WriteLine("Param i++ {0}", i++);
 Console.WriteLine("After Param i++ {0}\n", i);

 i = 0;

 Console.WriteLine("Param ++i {0}", ++i);
 Console.WriteLine("After Param ++i {0}\n", i);

 i = 0;

 Console.WriteLine("Statement i++ {0}\n", i);

 i = 0;

 Console.WriteLine("Statement ++i {0}\n", i);

Conclusion, be careful when writing code, don't assume that things work the same way when written differently.

Tuesday, June 7, 2011

DataTable.Compute() woes

So if you have ever seen this goddamn error before, then you might have been tempted to pull your hair out while screaming, "WHY WON'T THIS FUCKING WORK!" Especially when you see a goddamn example of it on the MSDN white pages:

For some people this is a very obvious error, "Oh stupid me, its so clear I am trying to take the sum of a column with a data type of string, oops!" But for people like me, when you are trying to get 100 things done all at the same time a stupid ass error like this can trip you up. So this is just a heads up on DataTables, make sure your DataTable's data is strongly typed so that you don't run into silly problems like this one.

Additionally when using the DataTable.Compute() method think of it this way: DataTable.Compute([Aggregate Function for ONE column only], [WHERE clause]), easiest way to think about it in my opinion. Keep it simple, no fancy stuff, this isn't real SQL.

Friday, May 27, 2011

Highlighting Syntax in Blogger and other Blogs

Ha found it already and I will figure it out later.

Multiple Lines to a Single Line using Powershell

#declare a variable to dump a text file into

#Pipe the file into the variable using the cmdlet tee-object and pump the unwanted output to (dev) null
cat temp.txt | tee-object -Variable a > $null

#Place the value into a string
[string]$strA = $a

#Print your string or store it to another file, either way it is now
#all on one line with a single CRLF at the end of the line
#print to screen


#output to file
$strA > onOneLine.txt

Update: Added the PowerShell brush for syntax highlighting

Yay another blog site about coding

This is the first post and I am going to just gloss over why I am creating this site. I am creating it to share things I find while I am developing other things. I like finding really obscure issues and just making people aware that they exist. I do not consider myself an authority on code, so please don't think everything I am saying is fact, just offering stuff for people to look at and maybe solve their problems too.

That being said there will probably be spelling mistakes, grammatical errors and other issues, but this site is not for philosophy of coding practices (I might contradict that later) it is for reference (right now) to just log things I find as I am working through out the day.

I have a lot of content I want to share and there are sites I would like to contribute to such as and other sites, but I don't have the time to go through the approval process at the moment. I will polish what I did later and possibly re post certain things I have here on