Monday, May 26, 2014

"object reference is not set to an instance" error on Feature Activation

Introduction

I am going to share some idea about resolving "object reference is not set to an instance" on Feature activate. On my case, I am having Feature event receiver with Some methods which is adding content to the pages. I was getting error with those method only. An "object reference is not set to an instance" has been cleared when i hidden those methods. Finally, I found the mistake where i did.

Solution

Just check the Feature scope and accessing Feature parent.

If your feature is having Site scope, 

 SPSite site = properties.Feature.Parent as SPSite

If your feature is having Web scope

 SPWeb web = properties.Feature.Parent as SPWeb;

At last, Check the AllowUnsafeUpdates before and after update.

In my case, I did the mistake in "AllowUnsafeUpdates" side. My issue has cleared once i set the UnsafeUpdates

Conclusion 

It is one of the solution to resolve the "object reference is not set to an instance" issue

Happy Coding.... !!!!

No comments:

Post a Comment