CK's Tech Blog
It's Microsoft's World, and I'm just living in it

Nullable Int type in C#

August 18, 2008 06:00 by ckincincy

I was recently doing some development that needed to allow for an int to be null.  However in .NET that isn't allowed by default.

So I started doing some searches and found that there is a way to have nullable types in C#.

There are two ways to do this:

1. Nullable<int> x = new Nullable<int>(125);

2. int? x = 125

Now what I find interesting is how you can find out if this is null.  You can do, again, one of two things.

1. if(x.HasValue).....

2. if(x != null)....

I actually prefer option two in both situations because that just looks normal to me. 

HT: Eric Gunnerson


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Quick Tip - Getting the most out of Visual Studio

August 14, 2008 06:00 by ckincincy

Great page to read to get the most out of Visual Studion.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Failed to access IIS metabase

August 10, 2008 06:00 by ckincincy

At work we've recently hired a few new developers and they got this error.

Having worked at setting up many development boxes in the past I knew what the issue was, but honestly I need to post about it so I have a quick reference to the fix... and I figured it may help you as well.

The problem?  .NET framework was installed before IIS.  The fix is pretty easy, you need to 'reinstall' the .NET framework.  Thankfully Microsoft makes it fairly easy.

Open up a command line and type the following and you will be good to go.

c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe -i

Which will look something like this after the fact:

image

More info here.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

How To List All Session Variables ASP.NET

August 6, 2008 06:00 by ckincincy

Recently I needed to display all Session Variables when a crash would happen.  A crash would happen and I have this website I was working on send me an email with the stack trace and now the session variables.  However I wasn't aware of how to list all session variables, so I went to my friend Google and came up with the following code:

string strSessions;
for(int i=0;i<Session.Count;i++)
{
       strSessions += Session.Keys[i].ToString() + " - " + Session[i].ToString() + Environment.NewLine;
}

Works like a champ!

HT: davidj.org


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Response.Redirect, Server.Transfer

August 2, 2008 06:00 by ckincincy

After recently launching a website, I had some built in error reporting in it.  Starting seeing a few 'Thread is being Aborted' errors.  I remembered dealing with this at my previous job and that it was related to the Response.Redirect call.

So hopefully with the help of a few of my readers we can put a list of issues related to the various calls that you can make to redirect a user to another page.

Response.Redirect
Response.Redirect was something I first used in classic ASP.  now due to the nature of that platform I didn't see any issues with it.  But in .NET its a different story.  Microsoft gives us a few versions of this call.

1. Response.Redirect("URL")  - The parameter is just the URL that you want the user sent to.  Pretty strait forward.
2. Response.Redirect("URL", true/false) - The second parameter is what causes the error above.  By default version one of this call sets the second parameter to true.  However what that does is 'abort the thread' so as your page goes down to the next call it will see that the page is being aborted.  By setting this to false, you fix the issue.  However this is not idea because by setting it to true you are getting a bit more overhead on your HTTP traffic because you are telling the server to continue the request. Even though you have moved on.

Server.Transfer
Server.Transfer is a lot like Response.Redirect in that you have two versions to call.

1. Server.Transfer("URL")
2. Server.Transfer("URL", True/False) - The second parameter determines whether or not you can use the objects (like text boxes) on the original page.  If it is set to true, you can use the objects.  If it is set to false, you can't.  Those items expire when the new page loads.

Comparisons
Now from my reading there are a few other distinct differences between the two.

1. Response.Redirect allows you to redirect to pages external to your site. The Server.Transfer HAS to be on your server.
2. Server.Transfer is just like Response.Redirect with a true passed in.  Except it doesn't throw the original error.  This allows you to save server resources as you transfer from page to page.

Well do you have anything to add?  Did I miss anything?

HT: Microsoft
HT: Karl Moore


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Uninstalling .NET framework

July 21, 2008 06:00 by ckincincy

I've had two interesting things happen to friends computers over the past few months.

First I got an email from my friends at Tin Roof (by the way, if you want to support a great charity... this is it) telling me that she needed to file an extension on her taxes before she leaves for Nicaragua on Tuesday. However when she started Turbo Tax she was getting an error.

Further investigation by me (via a VNC connection I set up with her a while ago) realized that this was a .NET error.

Turbo Tax spit out the following error: 20888 39915.  A Quick search of their site gave this article.  Basically blaming .NET and their solution has a link to a program that totally wipes out .NET from your system so you can start over.  I downloaded the program, ran it and then reinstalled .NET and her problem was fixed (well after I ran a reboot.bat file that was in the Turbo Tax installation folder, but that's another issue all together).

Then I have another buddy who had been using a program I wrote for my church to transfer files between members of the multimedia team.  Several months ago a basic Windows component of it stopped working right.  I was at a total loss for a solution (as a simple uninstall and reinstall of .NET didn't help).  I let it drop... but I emailed him today with this fix and my hunch is, that this will get him up and running again.

What frustrates me the most about this, is that Microsoft's .NET uninstall doesn't fully uninstall itself.  Many years ago I did some work for Lexmark's All in One printers and one of the BIG things they did was make sure that their uninstall completely wipes out any record of the machine being on your system.  And really there is no excuse for any other behavior.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Firefox Bug

July 13, 2008 06:00 by ckincincy

Well this post is somewhat an archive for me in case it returns, but it may help somebody else.

Occasionally when I click external shortcuts on my system I will get the following Windows error:

"Windows cannot find 'www.example.com'. Make sure you typed the name correctly, and then try again."

Turns out this error is due to a Firefox 2.x bug.  Now I am not sure if it happens on 3.x (which I am running, but it is certainly something you can face on 2.x).

The fix involves a registry hack, but if you have any technical knowledge you can do it pretty easily.

View the fix.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Firefox | Microsoft
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Math with Doubles and Decimals in .NET

June 28, 2008 06:00 by ckincincy

Just before I went on vacation I had an interesting issue at work.

I was trying to multiple an int by a decimal.  Nothing big, but I kept getting this error:

Operator '*' cannot be applied to operands of type 'decimal'

I was floored, what do you mean I can't multiply a decimal in .NET?  What in the world are you talking about?

So after a brief search I found the fix.

Basically I had to add an M to the decimal.  So instead of:

4 * .95

I needed:

4 * .95M

Honestly still don't understand WHY Microsoft would think this is required, but they do. 

Hope this helps you as it helped me.

HT: Asp.net


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

It's Vista Dummy

April 24, 2008 19:09 by ckincincy

So the news out of Wall Street is that they are disappointed about Microsoft's financial numbers.

You read the article and they try to blame it on new pc sales.

I've got news for them, its all because of Vista... dummy.  I am a huge M$ supporter.  They have treated me very well in life.  The M$ technologies have made my professional life very good.  I love XP.  I even loved my Vista Business edition, but the bottom line is that Vista is a HUGE failure.  A failure similar to Windows ME and XP pre-SP1. 

I'm hesitant to buy a new PC with Vista on it.  I'd NEVER upgrade a PC to Vista.    I'd be more likely install Windows Server 2008 or 2003 before I'd even think about installing Vista.

Hopefully the next version of Windows is done right, M$ generally needs periods like this to get their game on.  And what I get from the community of Microsoft Developers is a huge turn around in how they do business in regards to developer tools, and the better the developers tools the better the operating system and applications that run on it.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Develop for Standards

February 24, 2008 22:33 by ckincincy

We are on the verge of two more browsers being released, IE8 and FF 3.  I've tested FF3 (as it was very easy to install without screwing up my current configurations), and have read up on IE8.  Both are aiming to be standards complient, FF 3 currently passes the Acid test, and IE 8 is reported to pass it.

Now here is the issue, IE 8 is not standard by default, you have to add a meta tag to your website saying it is compliant.  The thought is that they didn't want the web broken by the new browser.  

So here is my call to all developers... break the stinking web.  When you develop a site, make it 100% compliant to the standards and let the users stuck on old software deal with it.  We need to stop having to create hacks to work with the various versions of web browsers.

When I started out many years ago working in ASP I used GoLive; which my coworkers and I had two bits of fun with:
1. Had this saying: Be like Jesus, save often.
2. Called it GoDead due to its many crashes.

But GoLive was not standard compliant at all.  Now that I do my development in Visual Studio I make sure that all my sites are standard compliant.  So they should render perfectly in the new browsers.

But for those of you who develop websites, I repeat my plea: BREAK THE WEB. 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5