Wednesday, February 29, 2012

WSE: Server unavailable, please try later

This is an amazing gotcha that had me almost throw my computer off the sixth floor of my building. First to narrow down the steps I took in order to determine what was actually wrong:
  1. I regenerated my WSDL file
  2. I rebuilt my projects
  3. I closed visual studio and open it again
Unfortunately none of those things worked this time to fix the most useless WSE Exception of all time "Server unavailable, please try later"

It was later pointed out to me that I made a big mistake when putting together a public property in one of my classes that would be serialized by WSE for the WSDL definition. I was throwing an exception in the setter of my property. I did this on purpose because I didn't want anyone to use the setter. 

Well then why not just don't include the setter?
Ah, you see, if it were that simple then WSE wouldn't have been replaced by WCF and everyone would still be using it. WSE is pretty terrible for the record, but it is pre-WCF. The reason I didn't just exclude the setter is because WSE requires that all properties include getters and setters otherwise they will not be included - period.

The Mind Numbing Bug
Since I had both a getter and a setter - that part was okay - however I did have an exception being explicitly thrown in the setter so the client side would try to set the setter and it would throw an exception. The sad part is the exception that is returned is a silly WSE SoapException that simply says: "Server unavailable, please try later" - which is incredibly useless...

So here are the guidelines to using properties with WSE:
  1. Properties are not allowed to be Read Only if you want to use them.
  2. You are not smarter than WSE - if you are not going to use a setter or a getter then use a default of some kind - but do not throw any exceptions.
  3. If you want to hide a property from yourself in visual studio use the "System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)" attribute as highlighted here.
Why are you still using WSE? Didn't you know it is obsolete?
Yes, yes I know it is obsolete. It is not my decision to change the technology being used at my work place. I can make a plan for change and implement it slowly, but that is about it. So I am using it because it is part of a legacy system I am working on. Trust me I would rather be using WCF.

Tuesday, February 28, 2012

Windows Forms Project Crashes Immediately on Startup

This was a more puzzling error that I have had to deal with in a long time. Every time I started up my windows forms application I was getting an immediate "Object reference not set to an instance of an object" exception coming from the Designer file of one of my windows forms. This is probably the most frustrating place in the whole wide world for this to happen since designer classes are auto generated and you are not supposed to edit them. That last bit is a clue, the error isn't coming from the designer class because you are not supposed to edit it.

If you see a wretched error like this when you open your design view for a windows form:

Then it can be a few things, sometimes it happens for no reason at all and the best way to fix it is to close the window and re-open it. If it still gives you crap restart visual studio. If it still gives you a problem then you have a bigger problem. Lucky me, I had a much bigger problem. I created a custom control and added it to my windows form, but the catch is that the error didn't happen to me until later in the day - which makes absolutely no sense - this is a good example of something that should break but doesn't when it really really should.

It turns out that the designer file took the liberty of initializing a public property of my control to null, which in turn caused the "Object reference not set to an instance of an object" exception. I figured this out by commenting out the entire body of my control's class. It then revealed that the designer class was instantiating my public property to null for me without asking... I really didn't know it would do that, so be ware, the designer will instantiate your public properties for you.

I fixed this by wrapping the code that was blowing up in an If statement that made sure to check if that particular property was null. That fix this horrid problem.

Wednesday, February 22, 2012

How to convert a String (Char Array) to List of Int (ASCII Decimal Equivalent)

I think it confuses people that single characters are interchangeable with byte and int, so here I am telling you that they are interchangeable up to an ASCII limit of 128 characters. This means that you have 0 to 127 positive integers (characters) you can play with. Check out the table here.

One byte is 8 bits which is 2^8 which yields 256.

A signed integer (int) is 4 bytes long (32 bit) which is 2^32/2 - 1 which yields 2,147,483,647.

I am not saying: char == byte == int, but I am saying that they are interchangeable if used correctly. You can however say that a char < byte < int. In other words a char will fit in a byte or an int, and a byte will fit in an int, but not the reverse of that statement.

Here is a code example of converting a string to a List of int:

string temp = "ABC";

char[] arr = temp.ToCharArray();

List<int> lst = new List<int>();

foreach (char c in arr)

for (int i = 0; i < lst.Count; i++)
 Console.WriteLine("[{0}] = [{1}]", arr[i], lst[i]);

As you can see in the code above I am taking a character and storing it into a list of int. That is possible people of what I mentioned above. A character can fit into a int, and an integer up to the value of 127 can fit into a char.

This is particularly useful when you are trying to hash a string, serialize a string over a serial port or UART or do a number of other things.

Friday, February 10, 2012

CS0246: The type or namespace name 'NameHere' could not be found (are you missing a using directive or an assembly reference?)

This is a fun problem I ran into, luckily I solved it rather quickly.

The Setup
I have a website setup in IIS7.5 running on a .Net 2.0 application pool and I just added a virtual directory to it so I could add another application to the website running under a .Net 4.0 application pool. The website has its own web.config obviously and anything (applications) under the website's umbrella will inherit from the website's web.config by default.

I had to blank out some stuff for job security reasons. Sorry.

I was getting the yellow screen of death, name this error:
CS0246: The type or namespace name 'NameHere' could not be found (are you missing a using directive or an assembly reference?)
As you can see in the image it is complaining about the parent web.config and not the actual application web.config.

After looking at the website's web.config I noticed that it was clearing all namespaces prior to listing its own like below:

Website's Web.Config <pages /> Node


So noticing that, I took that same concept and put it into my own web.config like below.
The New Virtual Directory (Application) Web.Config <pages /> Node


Viola! Problem solved. This is certainly not a cure all for everyone's CS0246 problems, but it is definitely one of them. Kind of Obscure and not necessarily clear...

Thursday, February 9, 2012

HTTP Error 404.2 - Not Found, Error Code 0x800704ec

HTTP Error 404.2 - Not Found 
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list setting on the Web Server.
Error Code 0x800704ec

In order to fix this problem you need to do the following:

  1. Open up the IIS Management Console. Make sure to be at the server level. To do so click on the server in the left most pane.
  2. Double click on ISAPI and CGI Restrictions icon.
  3. Locate the assemblies that are not currently allowed, right click on them and in the context menu click "allow".
  4. If all is well your window should now look something like so:
Step 2.
Step 3.
Step 4.
I found the answer to this here for the record.

HTTP 404.17 - Not Found, Error Code: 0x80070032

HTTP Error 404.17 – Not Found
The requested content appears to be script and will not be served by the static file handler.
Error Code: 0x80070032

This especially obnoxious error occurs when you are trying to run a .Net application in IIS7. This happens because ASP.Net is not installed correctly for IIS7. The only solution I have seen here is to just repair the ASP.Net installation using the aspnet_iis -r command for your flavor of .Net.

Click Here for instructions.

If after doing the repair you get HTTP Error 404.2 then click here for the solution to that problem.

Repairing an ASP.Net installation for IIS7

This will more often than not fix many obscure and just plain ridiculous errors that IIS7 somehow manifests. I have worked with IIS7 plenty and I have seen it melt down plenty of times for which I will say aren't very good reasons. IIS7 is special...

Anyhow, to fix a what may seem damaged ASP.Net installation 2.0/4.0 do the following:
  1. Navigate to your flavor of .Net and CPU architecture directory using CMD or powershell:
    ASP.Net v2.0x86c:\Windows\Microsoft.NET\Framework\v2.0.50727\
    ASP.Net v4.0x86c:\Windows\Microsoft.NET\Framework\v4.0.30319\
    ASP.Net v2.0x64c:\Windows\Microsoft.NET\Framework64\v2.0.50727\
    ASP.Net v4.0x64c:\Windows\Microsoft.NET\Framework64\v4.0.30319\
  2. Enter this command: “aspnet_regiis –r”
Extra Precaution
When I did this repair once, specifically for .Net 4.0 I had a very unhappy surprise. All of my app pools that were running in 2.0 were magically changed to 4.0. That being said, as an extra precaution, Open up the IIS Manager and change all your APP Pools that were using 2.0, from 4.0 back to 2.0 since that repair command takes the liberty of changing all of the app pools without asking.

Tuesday, February 7, 2012

Can't Run Web Application After Renaming Web Project

This solution applies to many problems, but this one in particular. If you get a yellow screen of death when trying to run a Web Application in IISx that you just renamed, then chances are you didn't delete the old assembly from the bin folder prior to running the new one. Some additional detail about the yellow screen of death is it mentions something about a bad image format exception. That exception is always related to an assembly that .Net cannot load properly.

Simply put, delete the old assembly from your web application's bin folder. That should fix the problem.

Monday, February 6, 2012

Things Not Everyone Should Drink at Work: Chamomile Tea

I learned this the hard way a several years ago, but I was just reminded again when a coworker of mine brought in some caffeine free Chamomile Tea to work. Chamomile Tea makes you sleepy. It is a relaxer and sleep aid. "Okay... And?" you are probably thinking... well if you are already having trouble staying awake at work, then please for your own sake, don't drink Chamomile Tea at work. The tea in combination with the 2 O'Clock crash after lunch will lull you to sleep and you won't understand why until you read the wikipedia article on it. So this is indefinitely today's GOTCHA!

This of course doesn't happen to everyone. For example I drink double shots of espresso before I go to sleep, it doesn't keep me awake.

Friday, February 3, 2012

Credit Cards: How to use them Correctly

Credit Cards
Growing up I remember watching people get into varying amounts of debt with credit cards. Even my parents got into some troubles with credit, but along the way they explained to me the basis of how to use credit cards and I turned it into a science for myself. My mother to this day doesn't like that I pay off my whole bill early because she prefers to pay it off a week before it is due. Anyhow, I will explain my method of how to use Credit Cards correctly. I am not a financial expert, I am just a regular guy who really enjoys using his credit card in place of cash or a debit card. I think credit cards are incredibly convenient, a treat to use, especially with reward programs.

First Thing's First
If you do not have a bank account, you do not have enough liquid assets or a steady stream of income, then you should not use credit cards. If you still want to build credit then I suggest using prepaid credit cards such as a Rush Card. Russell Simmons made a great move to get people this service and it exists for people who fall into this category so that they can still build credit. You literally cannot go into debt with this type of card. If you do not have a bank account and you apply for a credit card chances are you will be denied and this looks bad on your credit.

Recommended Credit Cards
  • I do recommend American Express (Amex) and Bank of America (BOA). They both have incredible customer service, incredible rewards systems and incredibly easy to use websites. The flavor of your BOA card doesn't matter, but try to diversify so if you have a Visa already, get a MasterCard for your next card instead.
  • I DO NOT recommend Citibank - they flat out suck and are not a joy to do business with. Their website is beyond confusing and I never knew when my goddamn bill was due. Their customer service blows and they don't mind messing up your account, that you then have to clean up. I was with them for about 9 years until I realized how much I hated that account so I canceled it happily. When I canceled my account my credit score improved so all the people who say that canceling long running accounts will hurt your credit score aren't exactly correct it depends on your situation. I happen to have other cards that are 10+ years old. As long as you don't cancel your oldest card you should be fine, but even that I don't think is really 100% accurate. Credit is a funny thing.
  • I have only dealt with American Express, Bank of America and Citibank - no comment on anyone else because I haven't had any other.
  • Never pay an annual fee - there is just no point unless you receive a major benefit.
  • Make sure to get any rewards program available. Points, Cash Back, Air Miles - whatever it is free stuff. I prefer cash back and points because I can usually pay small parts of my bill off with them. Love my Amex.
Dispelling Misunderstandings of Credit Cards
  1. "Credit cards are evil!", Credit cards are not evil, people just make very poor decisions when using them. It is all about self control and listening to that little voice in your head that says "Don't do it! It's a trap!"
  2. "I am afraid to get into debt", that is nonsense because no one is forcing you to be in debt. That is the same as saying, "I don't want to lose all my money", well then simply don't spend all your money.
  3. "I was told that it is good to miss the first payment sometimes to build credit.", tell the person that told you that to jump in front of a bus every now and again. This is a load of bull, getting into credit card debt is considered bad debt, please don't do this. Good debt is considered a car payment, mortgage (when you can afford it) or student loans. You will build credit by using your cards regularly and paying off the balance in full. Ironically good credit card customers are the preferred customers of Credit Card companies. If you purposely go into debt, then sure it will show that you had a small loan issued to you on your credit, but in the long run I think you are just doing yourself harm. If you want to build credit via a loan - then get a loan - don't do this with credit cards.
  4. "When I get my bill I should pay it off immediately!", don't get into that pattern, there is a due date, pay the bill on time, but pay it when it is most convenient for you. I will explain more of this down below.
  5. "Aren't high Credit Card interest rates bad?" - Honestly, only if you intend on being in debt. If you are going to use the credit card as I am describing below - it won't matter what the rate is. I have had credit cards with 25% interest on them, I could care less because I never missed a payment.
The Golden Rules of Credit Cards
  1. YOU ARE BORROWING MONEY FROM YOURSELF! Don't think just because you have a 10,000 dollar limit, that you yourself have 10,000 dollars to spend that is simply your credit limit and nothing more. Your REAL limit is what ever assets you own IE: the money in your bank. So please for your own sake, don't go over any limits. You are lending money to yourself, so you pay your self back later. It is better to think of it that way so that you don't over spend. In all reality you are borrowing money from the credit card company, but again, you still have to pay off the balance - you just happen to be doing it at 0% interest before the due date.
  2. If you ever find yourself saying "I don't think I can cover this... oh heck I'll just put it on my credit card", you have failed yourself - time to cut up your credit card because you don't sound responsible enough to use one. That kind of mentality WILL get you into credit card debt which is a slippery slope since the APR is usually quite high. Climbing out of credit card debt is very difficult because the interest rates suck, you will get pounded every month unless you pay it off immediately.
  3. NEVER EVER spend more than you make in a month - UNLESS you planned on it IE: Large planned expenses such as a computer or other 1 time purchases.
  4. This is not really a credit card rule, but it ties in, make sure you have a buffer of cash in your account at all times and try to maintain it. For example, maintain a $2,000 balance and try not to go below it. In other words your $2,000 dollar balance IS your $0.00 mark.
  5. Don't open more than 4 accounts - this is a magic number I made up - just don't open more accounts than you can actually use in one month. You don't want to be overwhelmed with unnecessary bills. I currently only own 3 cards which I think is manageable. Fewer bills means more free time.
  6. Don't open a card to just take advantage of a one time offer. Only open the card if you intend on using the card indefinitely. I made this mistake once and I ended up closing my account like a year later because I wasn't using the card - this hurts your score don't do it.
Using your Credit Card
Simply put, use your credit card like it is cash in your pocket. When you have cash in your pocket, you can only spend what you have and most of the time you won't want to spend all of it. So just bare in mind, your limit is your bank account balance. I use my credit cards for ALL of my day to day expenses, especially large expenses because honestly who wants to walk around with wads of cash. Be weary of certain purchases that might incur a fee such as a "Cash Advance" purchase. Each credit card is different, but most of them will charge you for a "Cash Advance" such as certain types of gift cards. Usually the gift cards you buy in the stores are okay, such as Amex Gift Cards - but other types you can buy directly from banks, such as Chase Gift Cards which will cost you a Fee.

You don't have to feel obligated to use your credit card every month, I suggest using it when needed (every other month or every month doesn't matter), but don't let it go cold for more than 3 months. Meaning you need to have activity on your account or it could hurt your credit score. If you have a credit card that you don't use at all, consider closing the account before the company closes it on you. If a company closes a credit card on you - that is considered very bad.

Credit Card Budgeting
Make sure to have a credit card budget for all of your cards. This budget is a limit that you will set based on your spending potential, ability and comfort level. Make sure to base this figure on the rest of your set expenses and income every month. Use credit cards for day to day expenses such as gas, supplies, clothing and other essentials etc... If you do not make enough money, I would strongly recommend against putting your monthly bills (or any other frequency) on your credit card, those should all be Direct Debit or Automatic Clearing House (ACH). It is always safer to pay off non returnable items, that you will need regardless of your situation sooner rather than later. Make absolutely sure to check your credit card balance often to prevent overspending. Eventually you will know without checking about how much you have spent over the month. I usually keep a tally of how much I have in debt in memory at all times. If I forget I will just go check my account online. No debt is happy debt. It allows for a clear conscience and peace of mind.

When to use your Debit Card versus your Credit Card
I don't like using my debit card so I avoid using it most of the time because that is money you are dishing out immediately. The flip side to that argument is that when you use your debit card you don't have any debt to pay off, which only makes sense to me in very few situations which are:
  1. Non refundable items - such as food. You can't usually return food that you have eaten already. I mean you can try, but it might end you up in jail and that is just plain disgusting. Dining out is a good example too, going to a restaurant, going to a bar - you aren't going to be able to return those items as far as I am concerned there is no point in racking up debt on them. As mentioned before monthly bills fall into this category too. I am sure there are other types of non refundable items I haven't listed here, but you get the idea. If you have consumed the product already, it doesn't exist in it's original state after consumption and you cannot return it due to this fact - then use a debit card.
  2. You need cash back. This one is self explanatory, you don't want to go to an ATM, so you buy some stuff and get cash back. Simple.
  3. You have reached your set credit card budget limit for the month, time to switch to cash aka your debit card. It is important to not go over your budget, we all have those months though where there are just a bunch of unforeseen expenses, it happens, but don't go over your credit card budget for the month because it will be an annoying shock when you see the bill. I recommend switching to your safe option for the remainder of the month - using your zero debt option - your debit card (or cash).
Closing Dates and Due Dates (I have to rewrite this section - I'm sorry in advance)
I wish I could explain this better. The truth is I find this part annoyingly confusing so I will try my best to explain it, but take what I am going to say here - just this section - with a grain of salt. I believe that a voodoo ritual is performed when a closing date is chosen and your due date is finalized. Your due date will shift around, it changes month to month in a small window of time based on your Closing date. The closing date is when your rotating debt is being called in (this month's bill), everything you spend past that date will be on next month's bill. The due date should be no more than a week later (I think?), but I, nor the credit card companies or god himself can tell you when the due date lands. Okay I am being overly dramatic - but seriously I never know when exactly the due date lands because our calendar is silly. The good news is, they will tell you each month when your bill is due, so don't fret. Just make sure to pay your bill before the due date.

You are allowed to choose your Closing Date, just call the Credit Card company, speak to a rep and tell them you want your Closing Date to be on what ever date is most convenient for you. They might tell you that you can't choose your closing date in which case it is a different date - whatever the hell it is - it affects when your bill is due. Some date can be changed, they know what you are asking for, just gently push them in the right direction. 

Picking a Closing/Due Date Thingy
This is my preference, but I recommend trying to make ALL of your credit cards due at the beginning of the month. I used to have a credit card bill due every week, that just got annoying because I would find myself paying a bill each week - that is too much work. Pick a date, make them all due on that date, this is all stuff you purchased already, you just need to pay it off. I happened to pick the beginning of the month because I knew that I would be getting paid either that same Friday or next Friday. This leads us to payment...

Paying the Piper (or the Credit Card Company)
Well now that you racked up some monthly rotating debt, it is time to pay it off - all of it - not part of it, not 99.99% you want to pay of ALL of it as soon as conveniently possible for you before the due date. Luckily I have a strategy for this, but it really depends on your income and when you get paid. Like I mentioned previously pick a date and have all of your cards due the same date. If you get paid bi-monthly (every two weeks) then the beginning of the month, middle or end is fine. If you get paid monthly, first I am very sorry for you, I know that is annoying to deal with - try to figure out where it would hurt the least to pay off your credit card bills. The point is here that I like to choose a date close to pay day because I will schedule a payment for the same day that I get paid. The genius behind doing this is your bank account balance will actually reflect how much money you really have on pay day. You paid off your monthly bills, credit card debt, you used your debit card and now you got paid. Your ledger should now reflect how much money you really have - that is why I do it this way so I know where I stand accurately.

Credit cards are not evil, they are just ironic in two senses:
  1. You are borrowing money from someone to pay your expenses off with at 0% interest so long as you pay it back by a due date. So this is essentially a free service.
  2. The reason the service exists is because people fall into debt and they are the reason most of these services are free to begin with. Don't be one of those people.
As long as you don't overspend (overdraw) your account and you pay your bill in full on time; you will have access to an incredibly convenient financial tool forever. Credit cards are a very convenient and useful short term loan option. So just be a responsible consumer and only purchase things you need to purchase and plan those splurges (want as opposed to a need) and larger one time purchases ahead of time.

Thursday, February 2, 2012

How to use Treasury Direct

If you don't have an account yet...
I am not going to explain the registration process, that is pretty self explanatory, so if you don't have an account yet and you are reading this - go sign up for one first - unless you just want to peruse what I have here in which case you are more than welcome to.

If you do have an account...
The purpose of this article is to quickly explain some of the things that are not obvious enough on the site. I will only cover securities that I myself have already dealt with, I won't discuss any of the others because I don't want to give out what could be cloudy or falsified information. The screen shots seen below are from the Treasury Direct website and are shown only as a visual reference. I am not a finance expert and I am not giving any investment advice, this is simply a how to.

The Express Module
I don't recommend using this module right off the bat unless you are experienced with these kinds of securities and basically you know what you are doing. If you knew what you were doing you wouldn't be reading this How To by an amateur. I am saying not to use this module because I myself used this first when I just opened my account and I bought a 4 week bill for $100 at a 0.00% rate of return... yes you read that correctly - you can purchase bills are 0% interest.

Why the Hell do 0% Bills Exist?!
Simply put they exist because it is a safe investment for people who are looking for a safe place to store their money. People like me who don't have tons of money and actually want a rate of return are not one of those people. If you want to do more research on this just Google for 0% treasury bills. There are plenty of articles on it, I just happened to learn about it the hard way. In fact here is my email to the treasury when it happened:

My email to Treasury Direct about my unbelievable 0% Bill
I bought a bill using the express module. I was checking out the bill I invested in, but I see that it is at 0% interest? How can that be? Is that a bug on the site or did I really just give 100 bucks to the government to hold on to for me for 4 weeks at no return?
Their Response to my email:
Hello Eli,
Yes, you are correct the interest rate for four week bill's is currently 0%. 
Thank you,
<Name Purposely Removed>
Customer Service Specialist
Well as you would have guess that left me quite puzzled, after doing some research I fixed that. I do most of my best learning by trial and error... this just happened to be a really stupid way of finding out. Needless to say I will never make that mistake again, plus it was my motivation for this article.

How to Purchase Stuff Normally
1. Click on the "BuyDirect" link first
2. Use this page to make your purchases
In order to purchase your securities you want to select something from the radio button list and press the submit button. I have only worked with Bills and the Series I Bond so far. Purchasing the security is not the hard part, it is understanding the gravity of what you are purchasing that is difficult since the rates are not displayed for you at the time of purchase. You have to look that information up before purchasing anything.

Where do I find the Rates?
The links for the rates are inconveniently and inconspicuously scattered all over the site and unfortunately since it is a link it is hard to spot since it blends in with all of the other links that you are looking at on the site.   The developers really should have made it an image link - that is my biggest gripe about this site - understanding that the rates are on a different page all together! I really think they should show up at the time of purchase, logically I think that would make more sense than the user having to cross reference the rate themselves and still not being completely confident that - that was the correct rate.

So for your convenience here are the links:
Tentative Auction Calendar - This is a PDF
Auction Results - This link shows you rates

EE/I Savings Bonds
Savings bonds are a lot like Savings Accounts except that your assets are not liquid and there are penalties for getting your money back before maturity. So savings bonds are a hell of a lot more like Certificates of Deposit in my opinion, but again I am not a financial expert so if I am wrong forgive me. Just an observation...

Before you purchase these securities you should really know the following:
  1. You can purchase either security for a minimum of $25 and a maximum of $10,000 dollars. 
  2. Your purchase will not be redeemable (you can't cash out) until at least 1 year.
  3. If you redeem your bond before 5 years you will have to forfeit 3 months of your latest interest earnings (there are exemptions).
This information is here:
I-Savings Bonds
EE-Savings Bonds

I think the Treasury Direct site needs to be MORE clear about some of these things before someone takes the plunge. I am sure some people disagree with me, but from an ease of use point of view - this site is far from it. It is not friendly and you can pretty much screw yourself if you don't know what you are doing. The information I am pointing out above should be available at time of purchase.