In debugging my WebPart to see why its controls are not displaying, I put the page in edit mode in the browser to first remove all the superfluous instances of the WebPart so that I would step through the CreateChildControls() etc. methods only once.
On doing so, though (putting the page into Edit mode), I saw that each WebPart contained the following err msg:
Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type WebFormPDFGen.WebFormPDFGenWebPart.WebFormPDFGenWebPart, WebFormPDFGen, Version=1.0.0.0, Culture=neutral, PublicKeyToken=42314blabla could not be found or it is not registered as safe.
What? WebFormPDFGen.WebFormPDFGenWebPart.WebFormPDFGenWebPart is not found? The solution name is WebFormPDFGen, the WebPart is named WebFormPDFGenWebPart, and so are the .cs and .webpart files:
WebFormPDFGenWebPart.webpart does contain a reference to the unfindable entity (WebFormPDFGen.WebFormPDFGenWebPart.WebFormPDFGenWebPart):
<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="WebFormPDFGen.WebFormPDFGenWebPart.WebFormPDFGenWebPart, $SharePoint.Project.AssemblyFullName$" />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">WebFormPDFGenWebPart</property>
<property name="Description" type="string">My WebPart</property>
</properties>
</data>
</webPart>
</webParts>
So...is it that the webpart is not registered as safe, as the second part of the err msg mentions? What do I need to do to register it as safe?
UPDATE
I get the same issue at runtime with a very basic WebPart based on the walkthrough here:
When I add the WebPart to my test page, it renders fine - it has the expected "Hello, world!" message based on the code from that walkthrough, which is simply:
[ToolboxItemAttribute(false)]
public class XMLToPDFWebPart : WebPart
{
private string customMessage = "Hello, world!";
[WebBrowsable(true),
WebDescription("Displays a custom message"),
WebDisplayName("Display Message"),
Personalizable(PersonalizationScope.User)]
public string DisplayMessage
{
get { return customMessage; }
set { customMessage = value; }
}
protected override void CreateChildControls()
{
base.CreateChildControls();
LiteralControl message = new LiteralControl();
message.Text = DisplayMessage;
Controls.Add(message);
}
...but when I subsequently view the page when running the other project/WebPart, it not only no longer cheerily chirps, "Hello, world!" but it blasts the following foghorn in my face:
Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type XMLToPDF.XMLToPDFWebPart.XMLToPDFWebPart, XMLToPDF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=42f314BleeBlahBloo could not be found or it is not registered as safe.
Why does it now decide that the WebPart is lost or unsafe, when it displayed it before?
UPDATE 2
I got an err msg with a correlation number when selecting and 2-clicking the simple WebPart in the WebPart Gallery. These are the lines in the Log file that contain that correlation number:
03/24/2015 13:33:21.37 w3wp.exe (0x1980) 0x0320 SharePoint Foundation Logging Correlation Data xmnv Medium Name=Request (GET:https://duckbilled.platypus.poisontoe:443/_layouts/WPPrevw.aspx?ID=208) 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.39 w3wp.exe (0x1980) 0x0320 SharePoint Foundation Logging Correlation Data xmnv Medium Site=/ 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.43 w3wp.exe (0x1980) 0x0320 Document Management Server Document Management cm6w Medium Template Discovery/InitScriptData: cannot get user profile, no UserProfileApplicationProxy exists in the current context 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.43 w3wp.exe (0x1980) 0x0320 Document Management Server Document Management cm6w Medium Template Discovery/InitScriptData: cannot get user profile, no UserProfileApplicationProxy exists in the current context 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.45 w3wp.exe (0x1980) 0x0320 SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (EnsureListItemsData). Execution Time=11.0956839486583 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General avro High Relying on fallback logic in VghostPageManager::getGhostDocument() for document: 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\Features\XMLToPDF_Feature1\XMLToPDFWebPart\XMLToPDFWebPart.webpart' 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General 8kh7 High Cannot complete this action. Please try again. 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.46 w3wp.exe (0x1980) 0x0320 SharePoint Foundation General 8e2s Medium Unknown SPRequest error occurred. More information: 0x80070002 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.47 w3wp.exe (0x1980) 0x0320 SharePoint Foundation Runtime tkau Unexpected Microsoft.SharePoint.SPException: An error occurred when previewing the Web Part. at Microsoft.SharePoint.WebPartPages.WebPartPreview.CreateChildControls() at System.Web.UI.Control.EnsureChildControls() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 05556c29-2d56-4093-9a6a-15ed2346f3db
03/24/2015 13:33:21.57 w3wp.exe (0x1980) 0x0320 SharePoint Foundation Monitoring b4ly Medium Leaving Monitored Scope (Request (GET:https://duckbilled.platypus.poisontoe:443/_layouts/WPPrevw.aspx?ID=208)). Execution Time=208.394083605598 05556c29-2d56-4093-9a6a-15ed2346f3db
Note that if I try to add that WebPart to a page now, it tells me, "The operation could not be completed because the item was removed from the gallery"
UPDATE 3
Cleaning, rebuilding, and [re-]deploying seems to at least temporarily fix the new, super-simple WebPart:
...but my level of confidence that it will not become WebPart-non-grata is not exactly approaching Everest heights - maybe Mt. Timm.
As you can see, though, the original WebPart is still heaving an error.