Error : “Unable to start debugging on the web server…” ASP.NET 4.0

There aren’t many details here, but I was getting that same error while trying to Start Debugging on a web application project in Visual Studio 2010 that I’d just changed from 3.5 to 4.0. This solved the problem for me from the command line: cd %windir%\Microsoft.NET\Framework\v4.0.30319 aspnet_regiis.exe -i Just make sure to go into IIS … Read more

C# how to correctly dispose of an SmtpClient?

public void SendMessage() { using (SmtpClient client = new SmtpClient()) { client.Send(Message); } DisposeAttachments(); } That way the client will be disposed even if an exception is thrown during the Send method call. You should very rarely need to call Dispose explicitly – it should almost always be in a using statement. However, it’s not … Read more

When KeyNotFoundException is thrown, how do I see which key wasn’t found?

Custom exception: class WellknownKeyNotFoundException : KeyNotFoundException { public WellknownKeyNotFoundException(object key, string message) : this(key, message, null) { } public WellknownKeyNotFoundException(object key, string message, Exception innerException) : base(message, innerException) { this.Key = key; } public object Key { get; private set; } } Handy extension method: public TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) { … Read more

.NET 4.0 code contracts – How will they affect unit testing?

I don’t think unit testing and contracts interfere with each other that much, and if anything contracts should help unit testing since it removes the need to add tedious repetitive tests for invalid arguments. Contracts specify the minimum you can expect from the function, whereas unit tests attempt to validate the actual behaviour for a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)