Friday, May 30, 2008

Visual Studio : Snippets

This is for VS 2005.

Type a common keyword e.g.

for

Then hit the Tab key twice.

VS generates:



for (int i = 0; i < length; i++)
{

}



There's a whole lot of others listed here:

Enjoy!

.NET : Carraige return in textbox

I can never remember whether the CR symbol is "/n" or "\n".

Then I discovered that you could say:

txtResult.Text = txtResult.Text + "blah" + Environment.NewLine;

Much easier to remember.

Enjoy!

.Net : Active Directory error 0x80005000

Busy with an Active Directory project in Visual Studio 2005 when I got this error:

System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)

Bit of research on Mr. Google and I discovered that my url was something like:

string connectionString = "ldap://blah.local/CN=xxxx Users

when I should have had:

string connectionString = "LDAP://blah.local/CN=xxxx Users

i.e. "LDAP" needs to be in caps.

Enjoy!

Tuesday, May 27, 2008

C# : Simple logging framework

Java of course has Log4J and C# has Log4NET but if you are after a simple, cut down, no bloat framework have a look at:

a .NET logging framework

As the author states:


Why should I use this framework?

How popular is it?
Real companies building real applications use this framework. Most people who evaluate this framework choose to use it.

There is another popular framework with a download of several megabytes(!!), while yours is only about 100K (the DLL itself is only 40K). What gives?
With this framework you get a framework. Out of the box you'll be able to accomplish 99% of your logging tasks. Yet it isn't bloated with unnecessary complexities. For the 1% of other logging tasks you might have, you can easily extend it.


Having used it, yes it works, yes it's simple, yes it did what I wanted!

Enjoy!

Wednesday, May 21, 2008

.NET : Debugging a dll in Visual Studio 2005

So I wrote a .dll in C# (a class library project) which is called by a desktop application.

I set the Visual Studio debugger on the dll code, started the application and ...

nothing happened.

So off to Mr. Google and the answer is that you:

* Right click on the dll project in Solution Explorer.
* Click "Properties"
* Click "Debug"
* Click "Start External Program" and then browse to the application
* Save

Now when you hit F5 (Start Debugging), Visual Studio will start the application and the dll code will breakpoint.

Enjoy!