Object reference not set to an instance of an object

The infomous Object reference not set to an instance of an object error occurs when you try to reference or use an object that has not been set to a valid "value" or instance.  For example, let's assume you have a Class "Person" that has a property Name.  If you try to access the Name property and your Person object is not set to an instance, you will receive the Object reference not set to an instance of an object error.

In code:

Person p = null;
p.Name = "John Doe";

This is an obvious case, but what makes this error difficult to track down at times is when you do not know why you do not have an instance of the object.  This can occur for a variety of reasons.  If you are able to create a unit test (or already have one) this can help you to track down the root cause.  You can also rely on the stack trace and/or debug the offending code.

Passing Oracle Certified Programmer for the Java 2 Platform SE 6.0

A while back I passed the Oracle Certified Programmer for the Java 2 Platform SE 6.0 (formerly SCJP 6) exam and thought that overall it was a challenging exam.  The questions required you to have a good handle on the language and framework but you really needed to concentrate on each question and look for small details that would result in the correct answer.  

As for content, if you follow the SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates book that will give you a good start on the content.  I also recommend a mock test, such as the one offered by whizlabs.  I used this and found it to be helpful to familiarize myself with the exam format.  Javaranch is also a good resource.

SCJP 6 Exam Simulator http://www.whizlabs.com/

http://www.javaranch.com/

Good luck!

Passing Exam 70-523 Upgrade: Transition Your MCPD .NET Framework 3.5 Web Developer Skills to MCPD .NET Framework 4 Web Developer

I recently passed exam 70-523 to earn my MCPD .NET Framework 4 certification.  The exam covers a fairly wide range of topics and the following provides an overview of the sections to expect on the exam.

There are 5 seperate tests that you will take during the exam and this includes one real world scenario statement follwed by 6 questions on the requirement statement.

The tests break down into the following:

  1. WCF with .NET 4 - approximately 20 questions
  2. Web Application development with .NET Framework 4 - approximately 20 - 30 questions including topics on MVC and Web Forms
  3. Accessing Data with Microsoft .NET framework 4 - approximately 20 questions including topics on EF, LINQ, and DataTables
  4. Designing and Developing Web apps - 20 questions + the real world scenario statement & quesitons

The exam was moderatly difficult but if you have about 1 years experience in .NET 4 including MVC, EF, LINQ, and WCF, and jQuery you should do OK and no need to get a vce or brain dump or anything like that.

Some additional resources I found helpful:

http://gregorsuttie.wordpress.com/2011/01/01/net-upgrade-exam-70-523/

http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-523#tab2

 Good luck!

ASP.NET MVC3 Parser Error Message: This method cannot be called during the application's pre-start initialization stage.

After upgrading to MVC3 I recieved the below error: 
Parser Error Message: This method cannot be called during the application's pre-start initialization stage.
This occured becuase I was using a custom membership provider:
<add name="MyMembershipProvider" ....
(Entry in web.config)To resolve, I added the following to the web.config:
<add key="enableSimpleMembership" value="false"/>
<add key="autoFormsAuthentication" value="false"/>
 The reason - security and membership settings are now defaulted so you need to override them. 
 

AspNetMembershipProvider for MySQL

If you use ASP.NET (webforms or MVC) you may want to use MySQL as your database.  One nice feature of .NET is the Membership Provider which takes care of authentication and authorization.  You can use MySQL to store the necessary informaion for the membership and role providers.  The below article details how to do this:
 
 
If you run into issues, make sure you copy the MySQLMembershipProvider and MySQLProfileProvider sections from the machine.config to your local web.config.  Once you do this, you should be all set.

Create a self signed SSL Certificate

 The steps below ouline how to create a self signed cert for use on your local development machine.  This will allow you to run local sites under HTTPS for testing purposes.

1.       Bring up a Visual Studio Command Prompt:  “All Programs>Microsoft Visual Studio 2008>Visual Studio Tools>Visual Studio 2008 Command Prompt” (substitute "Visual Studio 2010" where appropriate if using Visual Studio 2010).

2.       Execute the “makecert” command for your machine.  For this example the fully qualified host name, “yourdomain.com
 
”, is used as the certificate name:
makecert -r -pe -n "CN=yourdomain.com" -b 01/01/2008 -e 01/01/2050 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 yourdomain.com.cer

3.       Use the IIS Web Server Certificate Wizard by right clicking on the web site where you want to install the certificate.

4.       Steps to add the Certificate to the the website:

1.       Right click the the website.

2.       Select “Properties”.

3.       Select the “Directory Security” tab.

4.       Select “Server Certificate”  from the “Secure communications” section of the tab.

5.       Click “Next” on the intro to the Web Server Certificate Wizard.

6.       Check “Assign an existing certificate” and click “Next”.

7.       Select the certificate name you just created with “makecert” above and click “next”.

8.       Specify the SSL port.

9.       Review your selections and click “next”.

10.   Click “Finish” to end the wizard.


Client Certificate Installation

In order to use SSL without the warning/error messages that IE will display by default when the server’s SSL certificate has not been issued by a recognized Certificate Authority (such as Verisign, etc.); you will need to add the certificate created by makecert into the “Trusted Root Certification Authorities” store of your Local Computer.

The steps to do this are as follows:

1.      Open up mmc (type “mmc” at the run or command prompt).

2.       Select “File>Add Remove Snap-In…”

3.       Select “Certificates” from the “Available snap-ins” and click “Add”.

4.       Select the “Computer Account” radio button.

5.       Select “Local Computer”, then “Finish”, then “OK”.

6.       Open up the “Certificates>Trusted Root Certification Authorities>Certificates” branch.

7.       Right click on “Certificates” and select “All Tasks>Import…”

8.       Click “Next”

9.       Browse to the certificate file created by “makecert” and “open”.

10.   Click “Next”

11.   Click “Finish”

 

MVC3 Upgrade The type 'System.Web.Mvc.AcceptVerbsAttribute' exists in both

If after following the manual upgrade instructions you receive an error such as "The type 'System.Web.Mvc.AcceptVerbsAttribute' exists in both " you should try the following:

 

 

  1. Right click on the web site and view the properties -> and in the references section make sure you do not have duplicate references...if you do, delete one of them
  2. Check you bin directory, if you have System.Web.Mvc.dll in the bin, remove it (you may also need to remove System.Web.Abstractions.dll, etc.


    You should then be able to build 

 

Wordpress Pretty permalinks

If you would like to have "pretty" URL's in wordpress, you can configure this using the "Permalinks" setting in the admin site (wp-admin).  If you select the option "Month and name" this will result in pretty url's, such as category/news.
 
If when you do this, the pages do not load, then you may need to update your apache settings.  Below are the steps I followed.

Assumes you already have the mod_rewrite installed already.
 
  1. backup your .htacess file in the root directory of your wordpress site
  2. modify httpd.conf (this file should be in the conf dir under your apache install dir)
    uncomment:

    LoadModule rewrite_module modules/mod_rewrite.so
  3. modify httpd.conf
    Find the lines below and set AllowOverride to All
     #   Options FileInfo AuthConfig Limit
          AllowOverride All  
 
Now you can delete your .htaccess, go into the admin site, permalinks, select default, save, then select Month and name, then save.  A new .htaccess should be created and you should be in business. 
 

IIS localhost System.Net.Mail.SmtpFailedRecipientsException Unable to relay for

If you do development on your localhost and you want to test email, you can update your web.config as per below.  Note that you will need a directory of D:\Maildrop on your machine.  Doing this will result in emaills being delivered to the directory you specify.

You may receive Unable to relay for... errors and if you do, you can specify a from in the smtp element.

 <mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory" from="local@localhost">

<specifiedPickupDirectory pickupDirectoryLocation="D:\Maildrop"/> </smtp></mailSettings>