I have a usercontrol that needs to add content programmatically from the front end. It basically needs to write a 'note' to the 'Notes' node within the current page. The usercontrol is giving me an error and I think it is an issue in the code. Here's the code behind:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Umbraco.Web;
public partial class usercontrols_WebUserControl : Umbraco.Web.UmbracoUserControl { protected void create(object sender, EventArgs e) { //Get the current page ID var pageId = UmbracoContext.PageId.Value;
//get the content service from this.UmbracoContext.Application.Services var cs = Services.ContentService;
//Create content, pass in the parent id and the document type alias. var document = cs.CreateContent("Status-" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture), pageId, "StatusUpdate");
//Set the post propety document.SetValue("post", post.Text);
//Set the author ID document.SetValue("memberId", Member.GetCurrentMember().Id);
cs.Publish(document);
} }
I am getting:
Error creating control (~/usercontrols/AddNote.ascx).
Maybe file doesn't exists or the usercontrol has a cache directive,
which is not allowed! See the tracestack for more information!
The tracestack:
System.Web.HttpCompileException (0x80004005):
c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error
ASPNET: Make sure that the class defined in this code file matches the
'inherits' attribute, and that it extends the correct base class (e.g.
Page or UserControl).
at System.Web.Compilation.AssemblyBuilder.Compile()
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.Compilation.BuildManager.GetVPathBuildResult(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean
allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
at umbraco.developer.assemblyBrowser.Page_Load(Object sender,
EventArgs e)
I assume you have a macro that renders on a template or from withing a rich text editor on the frontend. Is this macro mapped corretly to the user control? And does the user control exist in the usercontrol folder in your umbraco installation?
Have you made a project, which uses xcopy to copy over the assemblies to the bin folder and user controls to the usercontrol folder?
Ok...since I'm a frontend guy on a dauly basis it's been a while since I've been having a look at user controls and c# code. I know I've seen this error before...
Try adding ?umbdebugshowtrace=1 to the url of the page your'e requesting and see if we get some more information in the stack trace. Also try having a look in the umbracoLog table and see if the reveals anything of interest.
It's usualy caused by some missing dll files...just hard to figure out what it can be.
The code looks fine to me at a first glance.
It know where to add the new node because it gets the page id of the current node in this variable
//Get the current page ID var pageId = UmbracoContext.PageId.Value;
The "CreateContent" method takes this PageId as the parameter to figure out, which node the content should be created beneath.
System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). at System.Web.Compilation.AssemblyBuilder.Compile() 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.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at umbraco.developer.assemblyBrowser.Page_Load(Object sender, EventArgs e)
I'm pretty stuck on what files I might have missing.
I only really have the usercontrol with the codebehind
I think the code behind is inheriting correctly but I could be wrong
Could you search the entire project to see if there is a AddNote.dll in the folder somewhere, which needs to be copied to the /bin folder of Umbraco?
The .dll file is created once you build your project so it's not something you add yourself. I'm feeling somewhat confident it's because this is missing from the bin folder that you get the error above.
I just created a new project called AddNote and then added a new item, web usercontrol and called that AddNote
I then built the project to create the dll.
If I add all the umbraco references in the code behind it wont build because this is just a standard project to make the user control and it doesnt have all the umbraco assemblies.
I copied the dll into the bin folder on my umbraco site, cleared the cache and rebuilt the site.
The error is still the same.
It's telling me that there is an inheritence issue in the stack trace
System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
is the dll just to register the usercontrol? If so, can I just do this in the web.config?
It's driving me mad, simple usercontrol and i can't get it working :-/
Usercontrol Error help please!
Hi all,
I have a usercontrol that needs to add content programmatically from the front end. It basically needs to write a 'note' to the 'Notes' node within the current page. The usercontrol is giving me an error and I think it is an issue in the code. Here's the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Umbraco.Web;
public partial class usercontrols_WebUserControl : Umbraco.Web.UmbracoUserControl
{
protected void create(object sender, EventArgs e)
{
//Get the current page ID
var pageId = UmbracoContext.PageId.Value;
//get the content service from this.UmbracoContext.Application.Services
var cs = Services.ContentService;
//Create content, pass in the parent id and the document type alias.
var document = cs.CreateContent("Status-" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture),
pageId,
"StatusUpdate");
//Set the post propety
document.SetValue("post", post.Text);
//Set the author ID
document.SetValue("memberId", Member.GetCurrentMember().Id);
cs.Publish(document);
}
}
I am getting:
Error creating control (~/usercontrols/AddNote.ascx).
Maybe file doesn't exists or the usercontrol has a cache directive, which is not allowed! See the tracestack for more information!
The tracestack:
System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). at System.Web.Compilation.AssemblyBuilder.Compile() 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.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at umbraco.developer.assemblyBrowser.Page_Load(Object sender, EventArgs e)
Can someone please help with this?
Thanks in advance!
Hi Roger
I assume you have a macro that renders on a template or from withing a rich text editor on the frontend. Is this macro mapped corretly to the user control? And does the user control exist in the usercontrol folder in your umbraco installation?
Have you made a project, which uses xcopy to copy over the assemblies to the bin folder and user controls to the usercontrol folder?
Looking forward to hearing from you.
/Jan
Hi Jan,
Thanks for your swift reply!
The macro is there and the usercontrol is mapped to it. The usercontrol exists in the usercontrols folder.
I've not made a project no.
I opened my Umbraco site in VS 2010 and added a usercontrol from there. The only files I had were the usercontrol and code behind.
Have I done something incorrect here?
Thanks
The other thing is, how does the code above know what node to add the note to?
Sorry, Tim helped me initally with it. I'm new to adding data programmatically in Umbraco :-/
Hi Roger
Ok...since I'm a frontend guy on a dauly basis it's been a while since I've been having a look at user controls and c# code. I know I've seen this error before...
Try adding ?umbdebugshowtrace=1 to the url of the page your'e requesting and see if we get some more information in the stack trace. Also try having a look in the umbracoLog table and see if the reveals anything of interest.
It's usualy caused by some missing dll files...just hard to figure out what it can be.
The code looks fine to me at a first glance.
It know where to add the new node because it gets the page id of the current node in this variable
//Get the current page ID
var pageId = UmbracoContext.PageId.Value;
The "CreateContent" method takes this PageId as the parameter to figure out, which node the content should be created beneath.
Hope this makes sense? :)
/Jan
Hi Jan,
The stack trace is:
System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). at System.Web.Compilation.AssemblyBuilder.Compile() 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.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at umbraco.developer.assemblyBrowser.Page_Load(Object sender, EventArgs e)
I'm pretty stuck on what files I might have missing.
I only really have the usercontrol with the codebehind
I think the code behind is inheriting correctly but I could be wrong
Roger
Aaah sorry I totally missed that you already had added the stack-trace. H5IS :)
What DLL's have you included? And do you get any build errors or warnings?
/Jan
Hi Jan,
No dll's I just created the control in VS2010 and added the ascx and cs files
Hi Jan,
No build errors that relate to the usercontrol at all
Could you search the entire project to see if there is a AddNote.dll in the folder somewhere, which needs to be copied to the /bin folder of Umbraco?
The .dll file is created once you build your project so it's not something you add yourself. I'm feeling somewhat confident it's because this is missing from the bin folder that you get the error above.
Hope this helps.
/Jan
Hi Jan,
I just created a new project called AddNote and then added a new item, web usercontrol and called that AddNote
I then built the project to create the dll.
If I add all the umbraco references in the code behind it wont build because this is just a standard project to make the user control and it doesnt have all the umbraco assemblies.
I copied the dll into the bin folder on my umbraco site, cleared the cache and rebuilt the site.
The error is still the same.
It's telling me that there is an inheritence issue in the stack trace
System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
is the dll just to register the usercontrol? If so, can I just do this in the web.config?
It's driving me mad, simple usercontrol and i can't get it working :-/
I think there may be an error in this section of the code behind:
using Umbraco.Web;
using Umbraco.Web.UI;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace umbracoDocumentApi
{
public partial class usercontrols_WebUserControl : Umbraco.Web.UmbracoUserControl
is working on a reply...