Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Charles Jones 3 posts 73 karma points
    Apr 29, 2016 @ 20:19
    Charles Jones
    0

    'Umbraco' threw an exception of type 'System.NullReferenceException'

    Hello all... we have a very strange issue here that we need community assistance on:

    After upgrading from version 7.1.2 to 7.4.3 using nuget package manager and successfully loading the homepage and other views on the website, we started experiencing missing images on our custom 'product' view page.

    We traced the issue back to a RenderMvcController named ProductController.cs and have attached a screenshot of the specific error as shown inside of VS. To summarize, it appears Umbraco is somehow undefined and it fails wherever we use Umbraco.Media(). This is the only controller we use this in.

    Below is the offending line of code and the error. Nothing in this code has changed at all (along with every other model, view, and controller). We are using uCommerce for eCommerce purposes but I am not suspecting this as the cause at this point. Also, I have tried replacing Umbraco.Media() with MediaService calls and MS also throws the Null exception.

    Any direction would be GREATLY appreciated!

    THE LINE OF CODE: summarized custom controller THE ERROR: error as seen in visual studio

  • Nicholas Westby 2054 posts 7104 karma points c-trib
    Apr 29, 2016 @ 23:23
    Nicholas Westby
    0

    Can you try putting Umbraco on its own line just to be sure the problem is actually with that and not with the media? For example:

    var helper = Umbraco;
    var media = helper.Media(swatchImage);
    var url = media.Url;
    

    Sometimes the debugger can lead you astray, so splitting it into multiple lines should help confirm that the problem is actually with the Umbraco helper.

  • Charles Jones 3 posts 73 karma points
    Apr 30, 2016 @ 00:32
    Charles Jones
    0

    Thanks for the reply.

    This seems to return the same error as well. I did notice that in the Locals panel that this error is shown for several other items.

    Screenshot: enter image description here

  • Charles Jones 3 posts 73 karma points
    May 01, 2016 @ 15:36
    Charles Jones
    0

    I have resolved the issue by changing all methods to static and moving them into a new ShopController.cs non-RenderMvcController class and then fetching the media URL as follows:

    var uMedia = new UmbracoHelper(UmbracoContext.Current).TypedMedia(id);
    var url = uMedia.Url;
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies