• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1117
  • Last Modified:

Sharepoint - Webpart Error that happens after IISRESET

I kept getting this webpart error everytime I do an IISRESET. I've attached a screen shot.

A temporary fix I found is as follows:

1. Comment out all code from the webpart solution and only leave an empty CreateChildControls method there.
2. Build the solution and drop the dll into windows/assembly. Recycle AppPool.
3. Check to see that error is gone and webpart is empty.
4. Put the code back into the webpart solution
5. Build the solution and drop the dll into windows/assembly. Recycle AppPool
6. Check page to see that webpart is working properly.

After the fix, if I do an IISRESET, I get the webpart error again. If I do recycle then it'll be fine.
So, the webpart will work properly as long as I don't do IISRESETs.

What's going on?

Many thanks in advance, I've been stuck with this problem for months.
1 Solution


After placing your assembly to the GAC, you should add your webpart to the safe control list by adding a safe control entry for your custom assembly to the web.config file as follow:
<SafeControl Assembly="dll name", version=, Culture=neutral, PublicKeyToken=Replace it here form GAC" NameSpace="name space" TypeName="*" Safe="True" AllowRemoteDesigner="True"/>

After you have deployed your web part and registered it in the safe control , navigate to http://MyServer/_layouts/newdwp.aspx, where MyServer is the name of the server on which your sharepoint site is deployed.
Select the check boc next to MyNameSpace.MyClassName and then click PopulateGallery Button to add your web part in Gallery webpart.

for more information you can navigate to http://msdn.microsoft.com/en-us/library/ms415817.aspx
SOS_HelpdeskAuthor Commented:
Thanks for both your replies. I've been to two out of the four sites you guys suggested and tried the solutions but it didn't work. The second solution sandipkharde suggested is how to add a webpart in general. The webpart I have is actually working, so the webpart is already in safe control and the webpart gallery.

The weird thing about my webpart is that it breaks AFTER an iisreset. Recycling the appPool doesn't break it. So I need to look into something deeper is what I think; what is iisreset doing that recycle isn't? Why does replacing the webpart with an empty one, then with one with code works?

To me, the situation looks like this...

1. After IISRESET, everything is forgotten, cache is cleared. Now when the webpart is loading for the first time, sharepoint finds an error, throws an exception, therefore I get the webpart error.

2. After I replace the webpart dll with an empty one and do a recycle on the appPool. Sharepoint approves the webpart (because it's empty, there is no error) so now the webpart works.

3. I replace the empty webpart with one that has code, but since sharepoint already approved this webpart, the webpart works.

4. Webpart continues to work until IISRESET is done again, clearing cache, etc.

I can't post my code for review so if this question is stuck, I would understand.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


I'm really trying to figure out what is going wrong here, but I just can't seem to see it either.
Recycling your app pool is the same as what IISRESET does, but then for all the w3wp worker processes. If you would place those dll's in the bin instead of the gac, when you would change your dll's IIS would automatically recycle your app pool to load those new dll's.

The only thing I don't really get about your error message: Is it the import of the webpart that won't work or the execution of it after an IISRESET?
SOS_HelpdeskAuthor Commented:

It's the import of the webpart won't work after the iisreset. I need to apply the hack fix so import works, then apply the logic.

Thanks for your input. This looks like a deadend.
SOS_HelpdeskAuthor Commented:
Turns out it wasn't SharePoint related - I was working with an external library, and something was being declared too early.  Problem solved, thanks for your help

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now