PublishedElementExtensions Value<T> method throws NotImplementedException when using with IPublishedValueFallback
See original GitHub issueWhich Umbraco version are you using? (Please write the exact version, example: 10.1.0)
10.5.1
Bug summary
Hi, there is a strange exception after upgrading from 10.3.2 to 10.5.1.
Quick code review:
We have our BaseView that implements
private SEO? _seo;
public SEO SEO => _seo ??= Model is IPublishedContent content ? new SEO(content, new NoopPublishedValueFallback()) : throw new InvalidOperationException($"{nameof(T)} must implement IPublishedContent");
Which is derrived from SeoComposition, that is generated out of ModelBuilder.
Possible bug
In the interface IPublishedValueFallback
there is property IVariationContextAccessor VariationContextAccessor { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } }
This property is used in PublishedElementExtensions
method
public static T? Value<T>(
this IPublishedElement content,
IPublishedValueFallback publishedValueFallback,
...
EventuallyUpdateVariationContext(publishedValueFallback, culture, segment);
Since we can’t see if this is anywhere implemented, obviously we get NotImplementedException, which obviously throws this property if called without proper implementation.
I hope you can look into this issue, and that I explained properly what’s the issue, and possible cause of the problem.
Specifics
Possible cause? https://github.com/umbraco/Umbraco-CMS/commit/451d1cec6ab9ea3f1ea269fff3c4e95debfae5e7
Steps to reproduce
Our Issue:
When we call on page SEO.MetaTitle it goes through the code… then we come up to the method in generated composer
/// <summary>Static getter for Meta-Titel</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "10.5.1+c5fe779")]
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
public static string GetMetaTitel(ISeoComposition that, IPublishedValueFallback publishedValueFallback) => that.Value<string>(publishedValueFallback, "metaTitel");
Something happens when that.Value<string>(publishedValueFallback, "metaTitel")
is called with the publishedValueFallback
.
Expected result / actual result
No response
Issue Analytics
- State:
- Created 5 months ago
- Comments:7 (4 by maintainers)
Fixed in #14227
Hey,
I tried reproducing it and I got the same error. The reason for the error occurring is that you are using the NoopPublishedValueFallback, which doesn’t implement the new members added in https://github.com/umbraco/Umbraco-CMS/commit/451d1cec6ab9ea3f1ea269fff3c4e95debfae5e7. However, NoopPublishedValueFallback is only intended for testing purposes.
A solution could be changing your BaseView to something like this:
Note that this gets an actual PublidhedValueFallback instead of the NoopPublishedValueFallback.
I will create a PR that makes the NoopPublishedValueFallback implement the new interface member.