Building generic custom widgets with web admin only, getting 'Could not load' error

Fabio Goto asked on July 19, 2018 13:42

Hi!

I'm a complete noob with Kentico and I'm having an issue implementing a "generic" web part + widget following this tutorial here: https://www.mattnield.co.uk/blog/generic_web_parts_for_rapid_development.

It's either a problem loading the "GenericWebpart" or "CallToActionButton", with a "[Error loading the WebPart 'GenericWebpart' of type 'GenericWebpart']" error.

By following this tutorial, should this web part + widget work out of the box, or I'd have to code a bit for it to work?

I've been assigned to work on a project using Kentico, but I've no experience with C# and ASP.net (I come from a mostly PHP and Node background).

With static web pages I did not have any problem, but using widgets and other items is where I'm stuck.

Kinda tough situation, tbh.

Thanks.

Correct Answer

Brenden Kehren answered on July 19, 2018 22:38

So it appears you have a web site so manually adding the files through the UI is fine. I'd check in the /CMSWebParts/General directory and make sure GenericWebpart.ascx and GenericWebpart.ascx.cs files exist.

Second thing to check is to make sure in the GenericWebpart.ascx file in the declaration line at the top, you have the full path to the .cs file. Should look like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_General_GenericWebpart" CodeFile="~/CMSWebParts/General/GenericWebpart.ascx.cs" %>

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on July 19, 2018 17:41

You need to have physical web part code added to the file system. In Matt's article, he first mentions creating new webpart. If you didn't select the "Generate new files" you won't have any files in the file system and will get an error.

Have you checked the event log in Kentico? This can have a lot of good information for you if it's throwing errors like that.

0 votesVote for this answer Mark as a Correct answer

Fabio Goto answered on July 19, 2018 21:32

Thanks, Brenden!

I did select "Generate new files" and checked for them in the designated folder, and they're there. Save for creating them, like in the tutorial, I did not touch the .cs code.

Here's the description of the one of the errors I've had:

Message: Could not load type 'CMSWebParts_General_GenericWebpart'.

Exception type: System.Web.HttpParseException
Stack trace: 
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)
at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse()
at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
at CMS.Base.Web.UI.ControlDefinition.Load(Page page)
at CMS.Base.Web.UI.ControlsExtensions.LoadUserControl(Page page, ControlDefinition control)
at CMS.PortalEngine.Web.UI.CMSWebPartZone.LoadWebPart(Control container, CMSWebPartZone zone, WebPartInstance part, Boolean reloadData, Boolean isVariant)

Message: Could not load type 'CMSWebParts_General_GenericWebpart'.

Exception type: System.Web.HttpParseException
Stack trace: 
at System.Web.UI.TemplateParser.ProcessException(Exception ex)
at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)

Message: Could not load type 'CMSWebParts_General_GenericWebpart'.

Exception type: System.Web.HttpException
Stack trace: 
at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)
at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)
at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)

I tried redoing the tutorial from scratch, installed Kentico on a VM locally to see if I "tainted" something, but got the same errors. :/

Maybe I skipped something or did not see something?

Thanks again! :)

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 19, 2018 21:38

Are you using a website or a web application? Difference is pretty easy to see in the file system. Let me know if there is an /App_Code directory in the file system or not. The error seems like you have a web application and it needs to compile those files into a dll before it can reference it, so you may need to get into Visual Studio to do some work before you go too much further.

0 votesVote for this answer Mark as a Correct answer

Fabio Goto answered on July 19, 2018 22:21

Thanks again, Brenden!

Yes, checking on the FTP, there is an App_Code directory in the project.

So now I've got to know what to do then. Since this project's been in the hands of two developers before me and I kinda fell into this job, so I'm pretty much lost, even after installing Kentico, reading some of the documentation and doing the tutorials.

I'm kinda being pressured to work on the remaining deadline. Will see what I can do here. :/

0 votesVote for this answer Mark as a Correct answer

Fabio Goto answered on July 20, 2018 04:29 (last edited on July 20, 2018 10:38)

Thanks again.

Just as you said, both files are there and the header of GenericWebpart.ascx has that first line.

Yet, I still have the [Error loading the WebPart 'GenericWebpart' of type 'GenericWebpart'] whenever I use a widget from the tutorial.

I also had [Error loading the WebPart 'CallToActionButton' of type 'CallToActionButton'] errors appearing, but on the tutorial it clearly states 'CallToActionButton' as a web part layout. 🤔

Maybe I'm overlooking things then?

0 votesVote for this answer Mark as a Correct answer

Fabio Goto answered on July 20, 2018 20:36

Ok, so I kinda deleted everything I created in both Kentico and physically, recreated the whole thing, and it worked.

Kinda puzzled, but if it works, well... :P

Thanks again for the heads up, Brenden. :)

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 20, 2018 20:52

So one think you'll find out with Widgets is no matter how much you change the back end configuration or webpart configuration, they will not reset any instances already on a page. You have to phyiscally go back to the widget instance on EACH PAGE you have them on and remove it and add it back.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.