Try our conversational search powered by Generative AI!

Content with id was not found for ContentReference.RootPage

Vote:
 

Hi all, 

We have a 2 websites with different code bases and structure. Site1 has a custom content provider that we want to implement in Site2. This custom content provider works fine in Site1.

However, when the code for the provider is copied over to Site2, it compiles ok but at run-time errors out when trying to create a folder under the rootpage. 

For additional info, we are using en-AU as Site2's default language and it also has custom routing in it - not sure if these have any bearing on why we are seeing this error.

Any ideas what might be causing this error and how we can fix it? 

Content with id 1 was not found

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: EPiServer.Core.PageNotFoundException: Content with id 1 was not found

Source Error:

Line 51: 		private ContentReference CreateRootFolder(string rootName, Guid rootGuid)
Line 52: 		{
Line 53: 			_contentRootService.Register<ContentFolder>(rootName, rootGuid, ContentReference.RootPage);
Line 54: 
Line 55: 			var fieldRoot = _contentRootService.Get(rootName);
#275573
Edited, Mar 03, 2022 4:28
Vote:
 

Hey Raquel,

I'd make sure that the Root content (ID 1) actually exists in the content tree and/or in the database. If you've done this and it does exist then there could be a problem that causes the incorrect content provider to be used internally to get the root content. What I mean is that it might be using your custom content provider to get the content with ID 1. Then presumably you get the error because the content does not exist at the source. 

What is the name of your custom content provider and how is it registered? There could be a problem with the name or the default content provider being overriden somehow.

As a side note, when retrieving content using a ContentReference the ProviderName property is used internally to get the content provider. You can get the provider name for the Root like so:

ContentReference.RootPage.ProviderName

Hope this helps 😁

#275577
Edited, Mar 03, 2022 6:20
Vote:
 

Hello Ynze, 

I have checked that there root content with Id 1 is actually on tblContent. It had fkMasterLanguageID set to 1 (en) but most of our content are in en-AU (id 16 in tblLanguageBranch).

I initially also thought that it may be causing Opti to not find the rootpage and I changed the fkMasterLanguageID to 16 but it is still not finding the root page. 

I have checked the rootpage's providername and it is null. Is this correct? 

The error is showing up because I am trying to create a custom folder under the rootpage for my content. Here's a snippet.

public void Initialize(InitializationEngine context)
        {
			_contentRootService = ServiceLocator.Current.GetInstance<ContentRootService>();
			_contentSecurityRepository = ServiceLocator.Current.GetInstance<IContentSecurityRepository>();

			InitializeBills(context);
		}

        public void Uninitialize(InitializationEngine context)
        {
		}

		private void InitializeBills(InitializationEngine context)
		{
			BillsRoot = CreateRootFolder("Bills", BillsRootGuid);

			var providerValues = new NameValueCollection();
			providerValues.Add(ContentProviderElement.EntryPointString, BillsRoot.ToString());
			providerValues.Add(ContentProviderElement.CapabilitiesString, "Search");

			var billsProvider = new BillsProvider(context.Locate.ContentTypeRepository());
			billsProvider.Initialize("Bills", providerValues);

			var providerManager = context.Locate.Advanced.GetInstance<IContentProviderManager>();
			providerManager.ProviderMap.AddProvider(billsProvider);
		}

		private ContentReference CreateRootFolder(string rootName, Guid rootGuid)
		{
			_contentRootService.Register<ContentFolder>(rootName, rootGuid, ContentReference.RootPage);

			var fieldRoot = _contentRootService.Get(rootName);
			var securityDescriptor = _contentSecurityRepository.Get(fieldRoot).CreateWritableClone() as IContentSecurityDescriptor;

			if (securityDescriptor != null) { ..}
                 }

It fails and I get this error,

Content with id 1 was not found
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: EPiServer.Core.PageNotFoundException: Content with id 1 was not found

Source Error:


Line 52: 		private ContentReference CreateRootFolder(string rootName, Guid rootGuid)
Line 53: 		{
Line 54: 			_contentRootService.Register<ContentFolder>(rootName, rootGuid, ContentReference.RootPage);
Line 55: 
Line 56: 			var fieldRoot = _contentRootService.Get(rootName);
#275796
Edited, Mar 07, 2022 5:53
Vote:
 

Hi Raquel,

In this instance the ProviderName should be null.

I'm almost certain you're onto something with the language, what is the value of EPiServer.Globalization.ContentLanguage.Instance.FinalFallbackCulture? Is it en-AU? My guess is that it's a value that the root doesn't exist in, because your code looks correct here.

#275856
Mar 07, 2022 20:39
Vote:
 

Hello Jake, 

I have changed the language in the Root Page to be en-AU and have also changed the language for it in the db, 

update tblContent set fkMasterLanguageBranchID=16 where pkID=1

update tblContentLanguage set fkLanguageBranchID=16 where fkContentID=1

update tblWorkContent set fkLanguageBranchID=16 where pkID=1

Checking EPiServer.Globalization.ContentLanguage.Instance.FinalFallbackCulture after these changes return en-AU. 

However, I am still getting the same error. Is there anything else I might have missed?

#275952
Mar 09, 2022 0:48
Vote:
 

Can you confirm from the CMS that your root page is now en-AU (it should be given those db changes):

What about if you use the content loader to get the root yourself, presumably that also doesn't work? If it does, what language does it resolve in?

_contentLoader.Get<PageData>(ContentReference.RootPage);

If your root page is in en-AU and your first enabled language branch is en-AU (which it is baed on your FinalFallbackCulture) I can't see why this wouldn't work.

#275954
Edited, Mar 09, 2022 9:48
Vote:
 

I recently ran into this issue myself. The solution was to add the following attribute to my initialization module class:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]

The documentation states — at the bottom of this page — that the dependency is required when using the CMS API in your module.

#284347
Jul 25, 2022 1:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.