question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PublishedElementExtensions Value<T> method throws NotImplementedException when using with IPublishedValueFallback

See original GitHub issue

Which 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:closed
  • Created 5 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nikolajlauridsencommented, May 10, 2023

Fixed in #14227

1reaction
andr317ccommented, May 10, 2023

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:

public class BaseView<T> : UmbracoViewPage<IPublishedContent>
{
    private SEO? _seo;
    public SEO SEO => _seo ??= Model is IPublishedContent content ? new SEO(content, Context.RequestServices.GetRequiredService<IPublishedValueFallback>()) : throw new InvalidOperationException($"{nameof(T)} must implement IPublishedContent");
    
    public override Task ExecuteAsync()
    {
        return Task.CompletedTask;
    }
}

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

11.4.1 dotnet new umbraco
PublishedElementExtensions Value<T > method throws NotImplementedException when using with IPublishedValueFallback · Richtext editor toolbar icons ...
Read more >
NotImplementedException Class (System)
The NotImplementedException exception is thrown when a particular method, get accessor, or set accessor is present as a member of a type but...
Read more >
Software-update: Umbraco CMS 11.4.1
PublishedElementExtensions Value<T > method throws NotImplementedException when using with IPublishedValueFallback · Richtext editor toolbar ...
Read more >
Why does NotImplementedException exist?
For example, Visual Studio will explicitly implement an interface's methods/properties with the body throwing a NotImplementedException.
Read more >
Use of NotImplementedException
I am the "hard error" type of guy: I will throw an exception at the slightest hint that something might be wrong; I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found