tips for debugging and fixing code

Exceptions! enable checking of clr exceptions
Make use of your debugger, and sometimes it’s better to fix the symtoms, save time if you can.
upgrade your hardware to make debugging smoothly, it’s frustrating if everything is slowww
always refactor the code first, break it into smaller pieces and rename variables, don’t stress your brain
print out exceptions and errors, don’t rely too much on the debugger, those are unreliable at times.
make small changes one at a time, dont make too many changes unless you are sure.
learn SQL, group by, join, etc. It helps to fix performance problems, also review your algorithm complexity theories.

Use WinMerge to check for differences in pieces of code when trying to eliminate duplicates of code

Webpart not registered as safe, safe control

Safe control troubleshoot checklist

-Make sure the site URL is correct, don’t deploy to the wrong site and expect it to work

-The namespace in .webpart and Element.xml files are correct.

Sometimes re-activating the feature may help.

If you renamed the webpart in Visual Studio, do a Find All in file and search for the old webpart name to make sure all references are updated.

Tips to improve performance of Virtual Machine

coding horror link

Run the VM on a seperate hard drive, this will improve the disk IO since the host machine’s hard drive and the VM’s can spin separately from each other.

If possible, use an external SSD drive, especially for Sharepoint development. SSD will improve performance dramatically.

Make sure your VM have sufficient RAM for development. Upgrade the host machine to have more RAM and allocate more to the VM helps a lot.

Optimize the VM’s OS and app settings, disable unused services and applications.

Sharepoint webpart validation prevents page from saving

To fix this problem. Check if there are validators preventing the page from saving, put in fake data to stop validation.

When developing webparts, put in code to disable validators while in edit mode.

//if we are not in display mode disable all the validation controls to make sure saving the page the webpart is on works.
if (SPWebPartManager.GetCurrentWebPartManager(Page).DisplayMode != WebPartManager.BrowseDisplayMode)
{
    foreach (var validator in Controls)
    {
        if (validator is BaseValidator)
        {
            ((BaseValidator)validator).Enabled = false;
        }
    }
}