0

I am currently experiencing the following error in Umbraco:

2016-12-12 11:45:56,665 [P10884/D3/T68] ERROR Umbraco.Core.Dynamics.DynamicInstanceHelper - An error occurred finding and executing extension method "FirstOrDefault" for type "Umbraco.Web.Models.DynamicPublishedContent". Types searched for extension methods were Umbraco.Web.Models.DynamicPublishedContent.
    System.MissingMethodException: Method 'Umbraco.Web.Models.DynamicPublishedContent.FirstOrDefault' not found.
       at Umbraco.Core.Dynamics.DynamicInstanceHelper.FindAndExecuteExtensionMethod[T](IRuntimeCacheProvider runtimeCache, T thisObject, Object[] args, String name, IEnumerable`1 findMethodsOnTypes)
       at Umbraco.Core.Dynamics.DynamicInstanceHelper.TryInvokeMember[T](IRuntimeCacheProvider runtimeCache, T thisObject, InvokeMemberBinder binder, Object[] args, IEnumerable`1 findExtensionMethodsOnTypes)

It is logged about every 30 seconds, over and over, all day. I was wondering if anyone knows what this means? The site seems to be running fine, but I am slightly concerned as none of my other Umbraco installations have this particular error.

Ginger Squirrel
  • 663
  • 7
  • 22

1 Answers1

3

The problem is that you are calling extension methods on a dynamic. See these posts for details. They were helpful for me.

You should be able to use

Enumerable.FirstOrDefault(myListOfDynamicStuff);

instead of

myListOfDynamicStuff.FirstOrDefault();

The extension methods are bound at compile time. In order to be bound correctly, the types would have to match up. In your case, your myListOfDynamicStuff variable would need to implement IEnumerable. However, your myListOfDynamicStuff is a dynamic, and the types don't match. I like to use the more strongly typed IPublishedContent in umbraco. You can get the current page like Model.Content and you can use the umbracoHelper, Umbraco.TypedContent() to get nodes by id.

Umbraco has implemented its own FirstOrDefault for dynamics that isn't an extension method. My guess is that you are either missing a dll, a using statement, or a reference of some sort in your web.config. I would download a vanilla copy of umbraco that matches your site, and do a compare of all the files. My favorite tool for this is Beyond Compare. Pay special attention to the dlls in the /bin and anything missing from either the root Web.config or the Web.config in the /Views directory.

Community
  • 1
  • 1
bowserm
  • 1,046
  • 10
  • 25