Rational Dev

C# Programming Tips

List of .NET Exceptions and their Uses

A list of classes that derive from System.SystemException in the .NET framework. Has brief explanations of that they should be used for.

This larger list is everything derived from System.Exception.

Posted On: May 11, 2010 - 3:39am by Rational
( categories: )

C#: Constant String From a Constant Char

Have you ever wanted to use a char as a constant string and tried something similar to below, but can't because const string must be valid at compile time?

const string AcceptCommand = Keys.Enter.ToString();

The closest I have found on how to do this is:

private static readonly AcceptCommand = Keys.Enter.ToString();

Posted On: May 19, 2009 - 1:17pm by Rational
( categories: )

log4net Custom Logging Level

Do you want to extend the ILog interface to include your own custom logging level?

There is an example of how to do this in the examples that come with log4net. The example creates a Trace level. See examples\net\1.0\Extensibility\TraceLogApp.

Posted On: March 19, 2009 - 9:48am by Rational
( categories: )

C# Cloning

C# cloning is the concept of taking an existing object and then creating a new object and copying the data from the original object into the new object.

There is also the concept of a shallow and a deep clone. A shallow clone will retain references to the existing objects reference by the original object, whilst a deep clone also makes copies of referenced objects.

Here is a good article on different C# cloning techniques.

Posted On: January 8, 2009 - 4:50am by Rational
( categories: )

Toolbox For Visual Studio 2008 Crashes On Choose Items...

Visual Studio 2008 SP1 consistently crashed when selecting the Toolbox, "Choose Items...." option. It turns out that there is an issue with PowerCommands for Visual Studio 2008. Once I had uninstalled PowerCommands for Visual Studio 2008, "Choose Items..." began working again.

Here is the bug work item

Posted On: December 23, 2008 - 1:11am by Rational
( categories: )

SSL cannot be enabled when using a proxy

I was getting the "SSL cannot be enabled when using a proxy" even though I had not explicitly configured a proxy for my application.

It turns out that FtpWebRequest will use the IE proxy settings for your account by default.

See the Configuring .NET FTPS in FtpWebRequest to Ignore the Proxy Settings article to see how to get around this.

Posted On: September 25, 2008 - 7:01am by Rational
( categories: )

Configuring .NET FTPS in FtpWebRequest to Ignore the Proxy Settings

Here are some tips on how to configure FTPS for .NET using the FtpWebRequest object and ignore a proxy.

By default the proxy settings are picked up from your account's IE proxy configuration.

In .NET 2.0 + I tried the following code and it seems to work:


ftpWebRequest.Proxy = new WebProxy();

.NET 1.1 had the following method which was deprecated:


ftpWebRequest.Proxy = GlobalProxySelection.GetEmptyWebProxy();

FTPS didn't appear to work over the proxy for me. I got the error message "SSL cannot be enabled when using a proxy". I assume Microsoft intentionally meant this to happen as FTPS is meant to be a point to point protocol. I didn't find any documentation to confirm this though.

Posted On: September 25, 2008 - 6:59am by Rational
( categories: )

Implementing Multithreaded Singelton Pattern In C#

This is an interesting article on how to implement a Multithreaded Singleton in C#.

Posted On: July 5, 2007 - 7:42am by Rational
Syndicate content
Google

Navigation