One of my customer’s came up with a peculiar issue. They were having a number of custom web parts on their SharePoint site and everything was working great from the browser. But they had also created a timer job that enumerates web parts and it used to fail with these errors: “A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.” -and- “No Parameterless constructor is defined for this object.”
All the web.config entries were proper and also the website was working properly from web browser. After some troubleshooting, found that customer is having the web part assemblies in the BIN folder of the web application (under <drive>:\Inetpub\wwwroot\wss\VirtualDirectories\<port>\bin). They had a dependency on a 3rd party assembly which was not signed, therefore cannot put their assemblies in the GAC.
Now how does this translates to error from the custom timer job?
OWSTIMER is where the timer job is running, and when it accesses the WebPartManager, it tries to instantiate the web parts, and the web parts were deployed to the BIN directory of the web app. Since OWSTIMER is not a web application and does not know where is the BIN folder hosted so eventually doesn't have access to the web part and get this error.
You can read more about Assembly Placement at http://msdn.microsoft.com/en-us/library/2h3sywsc(VS.85).aspx.
So what was the solution in this case?
Hope this helps you save sometime while troubleshooting… as always… Happy Coding
Hi,
I'm not so sure whether the owstimer process does not know where the BIN folder is of a WebApplication. Since most of the time, timerjobs are running per WebApplication or per Service or per Farm meaning that actually have access to almost everything that is available in the WebApplication. I reckon that the problem is that the .dll is not signed and thus the timerjob cannot read that assembly that is probably used by the webpart assemblies.
I'm keen to know if that would be the problem..