U4-4928 - System.NotSupportedException: Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined.

Created by Flavio Spezi 15 May 2014, 14:48:07 Updated by Houssam Edelbi 02 May 2017, 10:20:35

I am the same issue of #U4-4424

When I trying to read "Url" property of media node when it haven't a uploaded file, Umbraco returns an Exception.

''' [NotSupportedException: Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined.] Umbraco.Web.Models.PublishedContentBase.get_Url() +508 '''

I'm developed website with "Umbraco 6.1.6" and MVC. Website works properly. Now I upgrade the website to "Umbraco 6.2.0": now website returns exceptions when the media don't contains any uploaded file. I'm checking "media.Url == null" to verify if there are a file uploaded to media. Not I receive Exception in this row code.

3 Attachments

Download ExamineIndex.config

Download ExamineSettings.config

Comments

Sebastiaan Janssen 19 May 2014, 09:52:42

Strange, this was updated in v6.0.0 already to throw this exception, see commit: 1de43347d5f18866d3169bda6f294688dc72142b

Do you have some example code that worked in 6.1.6 and not in 6.2.0 so I can check it out?


Flavio Spezi 19 May 2014, 10:30:58

I look that media.Url property returns null when media node has not uploaded file in Umbraco 6.1.6 and Umbraco 6.2.0 beta (approximately 3 week ago).

Very simply:


var myUrl = Umbraco.TypedMedia(1234).Url
// If media with id=1234 is "image" and "umbracoFile" is null (maybe string.Empty), I receive an exception.


Sebastiaan Janssen 19 May 2014, 11:18:28

What does your media type look like? Does it have the umbracoFile property on it?


Flavio Spezi 19 May 2014, 11:21:52

Yes. It is standard Image mediaType or its derived mediaType.


Eric Schrepel 24 May 2014, 04:00:03

Agreed, huge problem. No media items will display using .url or .umbracoFile properties; all Partials code was working fine in 6.1.6, not in 6.2.


Stephan 25 May 2014, 19:02:31

The NotSupportedException is thrown when var prop = GetProperty(Constants.Conventions.Media.File); is null. GetProperty returns null when the property does ''not exist'' on the content type, not when the value itself does not exist. So if you get the exception it would mean that the Image content type does not have an umbracoFile property.

Which does not make sense. Looking at DictionaryPublishedContent in PublishedMediaCache. Might be something wrong around line 518 and after, not creating the property if it has no value in Examine cache.


Stephan 26 May 2014, 14:01:43

Pushed 95b9a46b88d1afd56c1ec9b6cf17af7e78c40a78 to 6.2.1 and b1e879bf68a60711bfd7e9fa45b0291d2784737f to 7.1.4 - for review.


Sebastiaan Janssen 26 May 2014, 15:35:10

@zpqrtbnk Close, but no cigar. Try with a media item that never had a file uploaded to it. Then it will try to do a fallback but it still can't find anything and you get:

Server Error in '/' Application.

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 2:
Line 3: @{ Line 4: var myUrl = Umbraco.TypedMedia(1058).Url; Line 5: } Line 6:

Source File: d:\temp\UmbracoCms.6.1.6\Views\umbHomepage.cshtml Line: 4

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Web.Models.PublishedContentBase.get_Url() +159 ASP._Page_Views_umbHomepage_cshtml.Execute() in d:\temp\UmbracoCms.6.1.6\Views\umbHomepage.cshtml:4 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +96 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +259 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +93 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 System.Web.Mvc.<>c__DisplayClass1a.b__17() +23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +242 System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +242 System.Web.Mvc.<>c__DisplayClass1c.b__19() +21 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +175 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +23 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19 System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult _) +10 System.Web.Mvc.Async.WrappedAsyncResult1.End() +62 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 System.Web.Mvc.Async.WrappedAsyncResult1.End() +62 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +25 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +23 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


Stephan 26 May 2014, 15:37:54

Damn.


Sebastiaan Janssen 26 May 2014, 15:40:19

@zpqrtbnk Oh, forgot to say: in 6.1.6 it would just give an empty string in that case, or at least it wouldn't YSOD.


Stephan 26 May 2014, 15:47:28

It's fixed in 7 but not in 6 due to another issue with 6. Fixing.


Stephan 26 May 2014, 16:09:01

6.2.1 d631039c0dcdfcf3e9f4fa71c7ef43dcd578ca83 should fix.


Sebastiaan Janssen 27 May 2014, 13:24:04

Yup, much better, thanks!


Eric Schrepel 29 May 2014, 06:44:11

So just tried installing 6.2.1 update since 6.2.0 caused the URL error. Now I get no access to any media items at all, using either .umbracoFile nor .properties. Not throwing "error" like before, just no URL nor umbracoFile properties (so, hence, no links to any media items).


Sebastiaan Janssen 29 May 2014, 08:44:49

@Eric.Schrepel Worked in my testing so please give a code sample for me to look into.


Paul Stoker 29 May 2014, 14:36:11

@sebastiaan, I did the same as @Eric.Schrepel above and I still get an error. I'm hooking into the MediaService.Saved event with the following method and mediaItem.Properties["umbracoFile"].Value is always null

This is my method:

private void SaveMediaToCDN(IMediaService sender, SaveEventArgs eventArgs) {

foreach (var mediaItem in eventArgs.SavedEntities)
{
    var imageFile = mediaItem.Properties["umbracoFile"].Value.ToString();
    // Removed other code for brevity
}

}

It only seems to work correctly without additional MediaService events


Stephan 01 Jun 2014, 14:56:52

@Paul that's different... I suspect that Properties["umbracoFile"] now returns the default value for the property type, and the default value for a string is null. It might have returned string.Empty in the past so that would be a breaking change.

Unless you mean that it returns null even though you set a value for umbracoFile?


Eric Schrepel 01 Jun 2014, 15:14:33

Code sample (sent to Sebastian but also making sure it's in this thread):

var image = Umbraco.Media(item.thumbnailImage); var imglink = image.url; @* also doesn't work as .Url, .umbracoFile, and same for images or other non-image media *@

Affects all our Media types, which all have the standard umbracoFile property. Also using either Umbraco.Media or Umbraco.TypedMedia yield the same blank result.

I was initially thinking it could have something to do with us using the imageCropper on image media files (or DAMP in the distant past), but this also affects non-image media items (i.e. PDFs), and also media items created since having dropped DAMP long ago.


Stephan 01 Jun 2014, 16:34:34

What is the value of image.GetProperty("umbracoFile").DataValue?


Eric Schrepel 01 Jun 2014, 18:33:45

I'll create a duplicate environment on Monday to test that (we've rolled back to 6.1.6 already). My hunch is the answer is going to be a null or empty string again.


Stephan 01 Jun 2014, 18:36:20

One thing I'm still trying to figure out... This is ''after'' you've uploaded an image, right? So you create the media then upload an image yet umbracoFile remains null or empty?


Eric Schrepel 01 Jun 2014, 18:43:31

Haven't experimented with that. It is definitely happening with all media items that are already on our system (images, PDFs etc). I'll keep a duplicate environment running next time so can test more things (like creating a new media item to see if the error recurs); we just keep rolling back to 6.1.6 when we run across errors.


Stephan 01 Jun 2014, 18:57:13

OK - but for existing medias, they are supposed to have a file uploaded already, right?


Eric Schrepel 01 Jun 2014, 19:04:10

They all have existing files, yes. Can see them in windows explorer as various media/nnnn/filename.jpg for example. The media seem to display correctly in the media area of the ui, just not yielding the url or umbracofile properties in the razor partials and templates.


Stephan 01 Jun 2014, 19:10:13

Got it. Assuming media ID 1234 is failing (ID shows on the media "properties" tab), could you go to the dev section, Examine tab, Searchers, Internal Searcher, Search Tool, and search for "__NodeId:1234" with Lucene Search -- and report what you get?


Eric Schrepel 04 Jun 2014, 22:51:45

I'd do that but after the 6.2.1 update just now, the Examine Management tab in the UI is blank, only says "Indexers" and "Searchers" but none of the indexes/searches I have in place show up there. Search does work in the site though. As for the previous request, image.GetProperty("umbracoFile").DataValue yields the error "object' does not contain a definition for 'DataValue'".


Eric Schrepel 06 Jun 2014, 22:10:50

So we gave up on the 6.2.1 update, tried instead for a 7.1.4 update which seems to have taken pretty well after overcoming some hiccups. But the Media issue is the same (no URLs still). I was able to do the Examine Search as Stephan asked, here's a sample image (node id 17335) which displays correctly in the UI but yields no Url nor umbracoFile field:

id 17335 nodeName Fall Chinook BON WA Side Sept . 2013 -2 updateDate 2014-05-22T11:13:34 writerName eschrepel@nwcouncil.org path -1,17335 nodeTypeAlias Image parentID -1 __NodeId 17335 __IndexType media __Path -1,17335 __NodeTypeAlias image __nodeName fall chinook bon wa side sept . 2013 -2

Last notes: the image.GetProperty("umbracoFile").DataValue yields the same YSOD result as before. If I leave off .DataValue, the result is "Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty", not that that helps in any way, but perhaps.


Stephan 07 Jun 2014, 08:38:28

1/ the Examine search result you get is interesting. Since you get a result, your medias are indexed. But the result does not contain a value for umbracoFile, meaning that medias are not indexed properly. Are you using the stock Examine configuration or has it been modified?

2/ the fact that Examine has no value for umbracoFile is the cause for the missing URL.

3/ not sure I understand what's going on with DataValue. In 7.1.4 XmlPublishedProperty implements IPublishedProperty which ''does'' have a DataValue property. But it's not very important, since we know the cause of the URL error now, ie an Examine issue.

So... need to find out why Examine does not index umbracoFile propertly.


Eric Schrepel 07 Jun 2014, 19:44:05

On our 6.1.6 site (which is all working fine, we get the .Url property correctly), I had modified the Examine settings slightly to exclude a few node types, etc. (I've attached the .configs if helpful). The 6.2.1 update (which doesn't return .Url/umbracoFile value) used the same Examine settings. The 7.1.4 update I used all default .config files, so Examine was clean slate on that, though the site uses a copy of the database from our 6.1.6 site (it updated the database and aside from this issue, seems to work okay).


Stephan 10 Jul 2014, 08:53:18

Looking at ExamineIndex.config file... the InternalIndex indexes a limited set of fields:

And this set of fields does ''not'' contain ''umbracoFile'' so that would explain why that value does not go into the index. So we have, according to Umbraco, a sort-of-corrupted index where the media ''is'' in the index, but not its ''umbracoFile'' property.

Could you add that property to the list, rebuild the index, and check if it works?

That being said... I'm not sure why it worked on 6.1 and not on 6.2 anymore. What I suspect is that in 6.1, we falled back to loading medias from SQL in that situation, whereas in 6.2 we assume the cache should be clean. I'll have to check.


Eric Schrepel 10 Jul 2014, 22:44:36

So I added umbracoFile to the Examine index, rebuilt the index and verified the umbracoFile property was part of the index. Then upgraded the site to 6.2.1 (at which point the Examine Management dashboard page only lists the words Indexers and Searchers, without any links or ability to do anything, but that's a separate issue maybe).

Then tried two types of code to display the url or umbracoFile properties. The first is old code which we're trying to move away from (and had, as of 6.1.6). The old code works:

var image = new umbraco.cms.businesslogic.media.Media(1300); var link = image.getProperty("umbracoFile").Value.ToString();

The above code gives the right URL for that image.

But the newer code, which we have adopted everywhere on our site, yields an empty string:

var image = Umbraco.Media(1300); var link = image2.umbracoFile; @* nor do .url or .Url work *@

We don't additionally have to add url (and by extension, things like croppedImage which uses an imagecropper type) to the Examine index, correct?


Stephan 11 Jul 2014, 11:00:22

No, "umbracoFile" is all that's required to get image2.umbracoFile to work. The old syntax (umbraco.cms.businesslogic.media) directly fetches the media from the DB, bypassing Examine, which explains why it works. I still cannot imagine why the new syntax does not work.

What's up with the Examine Management dashboard? It should be working and if not, that might indicate that something else is wrong with Examine?


Eric Schrepel 11 Jul 2014, 16:13:36

I'm stymied by the dashboard problem; just looks like the attached screenshot, nothing clickable. I've compared various config files between our working 6.1.6, the non-working 6.2.1 and default configs from 6.2.1 install folder, everything seems correct. Search in the UI works fine. If there are any files that would be useful to see, I'd send them for sure.


Stephan 29 Jul 2014, 09:02:00

@Eric: I feel sorry -- cannot think of anything. Cannot find enough time for this issue right now. If still unsolved sometime in septembre ping me. You might have to send me the entire site + database if that's possible.


Eric Schrepel 29 Jul 2014, 16:41:18

Thanks for helping look into it; we're near Paul Sterling plus Mindfly and ProWorks folks here, I may bring it up with them as we consider small maintenance contracts for further Umbraco development here.


Eric Schrepel 03 Sep 2014, 18:55:31

@zpqrtbnk Stephan, if the offer's still open to examine our db/site, I'd make it available in whatever way is best (probably truncate our /media folder to just a few items, which would make the overall site size not crazy).

If not, or if any other thoughts came to mind, would dig it. We're still hanging at 6.1.6 since the 6.2.x and 7.x upgrades are both stuck from this issue. Or somebody said we should build a new 6.1.6 site entirely, then pull our existing db and content into it, then try upgrading that site? I'm unsure how to do that specifically, but we're happy to try anything.

Thanks for any assist or redirection. -- Eric


Asbjørn Riis-Knudsen 03 Sep 2014, 19:11:40

Have you tried 6.2.2? 6.2.0 and 6.2.1 contain a pretty bad bug regarding the usage of Examine for media items. This was fixed in 6.2.2.


Eric Schrepel 12 Sep 2014, 22:05:50

Finally had tremendous success today upgrading from 6.1.6 to both 6.2.2 then 7.1.6, and not getting the blank umbracoFile/Url property problem.

The steps I took:

#Replaced my /config/Examine*.config files with those from a fresh install package. We'd previously limited some fields to search on, but Stephan suggested the lack of umbracoFile as one of those fields could be causing problems. #In the UI, use Developer -> Examine Dashboard -> Internal Index -> Tools -> Rebuild Index (and repeat for External Index). To verify success, use the Search tools on that same dashboard and see if __NodeID is populated for media items. This had been empty on previous attempts to upgrade and seems pertinent. #In the UI, remove any "Examine Dashboard" or "Examine Index Admin" types of installed packages. We had both installed before getting to version 6.1.6, where that was built in. Was causing our 6.2.2 upgrade to not show the Examine Dashboard correctly. #Applied 6.2.2 (then 7.1.6) upgrade, and found our media items (and their .Url and .umbracoFile properties) intact.


Houssam Edelbi 02 May 2017, 10:20:35

Hey Guys!

I'm using umbraco 7.2.2 and i'm still getting this error. The scenario is as follows: I'm using Articulate plugin to import posts from a wordpress blog to my umbraco site. i'm trying to get the Url of images i've uploaded in the media folder from the articulate sourcecode but i'm getting this error. I have debugged and tried many different scenarios and spent like 18 hours on this but no hope. I need some help!


Priority: Normal

Type: Bug

State: Fixed

Assignee: Stephan

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.2.0, 7.1.3

Due in version: 6.2.1, 7.1.4

Sprint:

Story Points:

Cycle: