U4-3825 - Problem with Umbraco.TypedMedia?

Created by Kristian Ravnevand 09 Dec 2013, 13:29:08 Updated by Kristian Ravnevand 10 Dec 2013, 08:17:03

Duplicates: U4-3630

In a "dummy" Razor view:

var img = int.Parse(Model.Content.GetPropertyValue("photo").ToString());

Not working: @Umbraco.TypedMedia(img).Id

The old one works: @(new umbraco.cms.businesslogic.media.Media(img).Id)

Results in ysod:

Server Error in '/' Application. Value cannot be null. Parameter name: propertyType 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: System.ArgumentNullException: Value cannot be null. Parameter name: propertyType

Source Error:

Line 21: { Line 22: var img = int.Parse(Model.Content.GetPropertyValue(heltblank.C.content.PHOTO).ToString());
Line 23:

Not working: @Umbraco.TypedMedia(img).Id

Line 24:

The old one works: @(new umbraco.cms.businesslogic.media.Media(img).Id)

Line 25:

Source File: c:\Users\krirav\SkyDrive\umbraco-sites\heltblankUmbraco7Site\umbraco\Views\Theme\Bootstrap3\Article.cshtml Line: 23

Stack Trace:

[ArgumentNullException: Value cannot be null. Parameter name: propertyType] Umbraco.Core.Models.PublishedContent.PublishedPropertyBase..ctor(PublishedPropertyType propertyType) +62 Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty..ctor(PublishedPropertyType propertyType, Boolean isPreviewing) +18 Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty..ctor(PublishedPropertyType propertyType, Boolean isPreviewing, String propertyData) +21 Umbraco.Web.PublishedCache.XmlPublishedCache.DictionaryPublishedContent..ctor(IDictionary2 valueDictionary, Func2 getParent, Func2 getChildren, Func3 getProperty, Boolean fromExamine) +2391 Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.ConvertFromXPathNavigator(XPathNavigator xpath) +921 Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetUmbracoMedia(Int32 id) +350 Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetById(UmbracoContext umbracoContext, Boolean preview, Int32 nodeId) +9 Umbraco.Web.PublishedCache.ContextualPublishedCache`1.GetById(Boolean preview, Int32 contentId) +38 Umbraco.Web.UmbracoHelper.TypedMedia(Int32 id) +37 ASP.<>c__DisplayClass2.b__0() in c:\Users\krirav\SkyDrive\umbraco-sites\heltblankUmbraco7Site\umbraco\Views\Theme\Bootstrap3\Article.cshtml:23

1 Attachments

Comments

Shannon Deminick 09 Dec 2013, 21:53:17

Hi, this should never be used on your front-end

@(new umbraco.cms.businesslogic.media.Media(img).Id)

This will make many sql calls and the result is not cached.


Kristian Ravnevand 10 Dec 2013, 07:14:40

Hi Shannon. I don't use the umbraco.cms.businesslogic.media.Media, that was just to show that the media item existed and worked with the old method. The error occur on the @Umbraco.TypedMedia(img).Id line.

This error occur even if the media isn't deleted. So I don't think it's a duplicate, but I saw your comments on U4-3630 so it could be related, but I attached a screenshot to make my bad english clearer :-)


Shannon Deminick 10 Dec 2013, 07:20:05

It's all part of the same couple of issues, should be fixed. If you want to test the nightly tomorrow that'd be great. The stack trace you have means it's trying to retrieve the media item from the legacy umbraco.library - you should make sure you Examine indexes are rebuilt since it is much faster when it finds the media there instead. The error that you are getting is because it's trying to load the isDoc xml attribute from the XPathNavigator which doesn't match up. Anyways, should be fixed.


Kristian Ravnevand 10 Dec 2013, 08:17:03

Hi again. You're right of course. Tried to delete all the index files and publish the media file again, than it worked. Sorry for the fuzz and I'll test the fix from the nightly tomorrow (if I manage to reproduce the error).


Priority: Normal

Type: Bug

State: Duplicate

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.0.0

Due in version:

Sprint:

Story Points:

Cycle: