Strange error when trying to create content programatically
I have Umb 8 & Vendr working nicely. This morning, I have needed to create a node in the root of the website programmatically so create a method in my ApplicationComponent like this:
private void CreateSettingsSection()
{
using (var ctx = _umbracoContextFactory.EnsureUmbracoContext())
{
var settingsNode = ctx.UmbracoContext.Content.GetAtRoot().FirstOrDefault(x => x.IsDocumentType(Settings.ModelTypeAlias));
if (settingsNode == null)
{
var node = _contentService.Create("Settings", -1, Settings.ModelTypeAlias);
var result = _contentService.SaveAndPublish(node);
}
}
}
but the code fails to run due to a Vendr licensing issue (we dont have a license bought as yet, but I'm running it on localhost).
It looks like an event handler we have that runs on publish to enforce the max SKU's permitted by a license is having a problem as it seems to expect it running in a request context (which it is obviously plausable that this is not the case).
I'll add it to our issue tracker to review, but it will likely not be till after CG now so early next week before I get chance to review it.
Are you able to work around this for the time being?
Actually, I'm a little surprised that CanFingerprint is erroring really as we already null check the Request so not sure why it's throwing.
If you want to test a fix in the mean time, I've added a try catch to this to capture any faults. You can access this on our unstable nuget feed for the time being (it'll be release next week after v10 is launched as the unstable feed currently supports v10 RC)
Strange error when trying to create content programatically
I have Umb 8 & Vendr working nicely. This morning, I have needed to create a node in the root of the website programmatically so create a method in my ApplicationComponent like this:
but the code fails to run due to a Vendr licensing issue (we dont have a license bought as yet, but I'm running it on localhost).
Hey Ian,
It looks like an event handler we have that runs on publish to enforce the max SKU's permitted by a license is having a problem as it seems to expect it running in a request context (which it is obviously plausable that this is not the case).
I'll add it to our issue tracker to review, but it will likely not be till after CG now so early next week before I get chance to review it.
Are you able to work around this for the time being?
Hi Matt,
Yeah, no problem. This code is a nice to have, so I'll mark it TODO !!
Actually, I'm a little surprised that
CanFingerprint
is erroring really as we already null check the Request so not sure why it's throwing.If you want to test a fix in the mean time, I've added a try catch to this to capture any faults. You can access this on our unstable nuget feed for the time being (it'll be release next week after v10 is launched as the unstable feed currently supports v10 RC)
https://nuget.outfield.digital/unstable/vendr/v3/index.json
The build you'll want to install is v2.3.0-beta042
I'll re-review when I'm back to see if there is a reason it could still be erroring and if there is a better option than the try catch
Update Issue tracker link is https://github.com/vendrhub/vendr/issues/374
is working on a reply...