Copied to clipboard

Flag this post as spam?

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


  • Nitesh 9 posts 89 karma points
    Dec 06, 2018 @ 09:17
    Nitesh
    0

    Incorrect Syntax near '=' issue while reading Typed Media | CMS Version 7.2.0

    2018-12-06 11:24:19,670 [17] WARN umbraco.macro - [Thread 11] Error loading Partial View (file: ~/Views/MacroPartials/HomePromoBanners/HomePromoBannersMacro.cshtml). Exception: System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '='.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    at Umbraco.Core.Persistence.PetaPocoCommandExtensions.<>c__DisplayClass4.b__3()
    at Umbraco.Core.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Umbraco.Core.Persistence.Database.<Query>d__1c1.MoveNext()
    at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Umbraco.Core.Persistence.Repositories.MediaTypeRepository.PerformGetByQuery(IQuery1 query)
    at Umbraco.Core.Persistence.Repositories.RepositoryBase2.GetByQuery(IQuery1 query)
    at Umbraco.Core.Services.ContentTypeService.GetMediaType(String alias)
    at Umbraco.Core.Models.PublishedContent.PublishedContentType.CreatePublishedContentType(PublishedItemType itemType, String alias)
    at Umbraco.Core.Cache.CacheProviderExtensions.<>c__DisplayClass91.<GetCacheItem>b__8() at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Umbraco.Core.Cache.CacheProviderExtensions.GetCacheItem[T](ICacheProvider provider, String cacheKey, Func1 getCacheItem)
    at Umbraco.Core.Models.PublishedContent.PublishedContentType.Get(PublishedItemType itemType, String alias)
    at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.DictionaryPublishedContent..ctor(IDictionary2 valueDictionary, Func2 getParent, Func2 getChildren, Func3 getProperty, Boolean fromExamine)
    at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.ConvertFromSearchResult(SearchResult searchResult)
    at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetUmbracoMedia(Int32 id)
    at Umbraco.Web.PublishedCache.ContextualPublishedCache`1.GetById(Boolean preview, Int32 contentId)
    at Umbraco.Web.UmbracoHelper.TypedMedia(Int32 id)
    at ASP._Page_Views_MacroPartials_HomePromoBanners_HomePromoBannersMacro_cshtml.<>c__DisplayClass1.b__0(TextWriter __razor_helper_writer) in d:\WWW<WEBSITEFOLDER>\App\Views\MacroPartials\HomePromoBanners\HomePromoBannersMacro.cshtml:line 36
    at System.Web.WebPages.WebPageBase.Write(HelperResult result)
    at ASP._Page_Views_MacroPartials_HomePromoBanners_HomePromoBannersMacro_cshtml.Execute() in d:\WWW\WWEBSITEFOLDER\App\Views\MacroPartials\HomePromoBanners\HomePromoBannersMacro.cshtml:line 21
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
    at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
    at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
    at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
    at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
    at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
    at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    ClientConnectionId:65ac02dd-e359-481f-9d12-ddaf01717e66
    Error Number:102,State:1,Class:15
    

    The lines 21 & eventually 31 has the below call to typed Media: Umbraco.TypedMedia(imageId)

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Dec 06, 2018 @ 11:53
    Alex Skrypnyk
    0

    Hi Nitesh

    Can you show the code of file: ~/Views/MacroPartials/HomePromoBanners/HomePromoBannersMacro.cshtml

    Alex

  • Nitesh 9 posts 89 karma points
    Dec 09, 2018 @ 13:15
    Nitesh
    0

    Hi Alex,

    Below is the complete code:

    @{
        var languageCode = ContextHelper.GetLanguageCode();
        var currentPage = Model.Content;
        var Banners = currentPage.GetPropertyValue<nuPickers.Picker>("LargePromo").PickedKeys;
        if ( Banners != null && Banners.Any() )
        {
            var oneBanner = Banners.Count() == 1;
    
            <div class="container-fluid">
                <div class="gallery">
                    <div class="slides">
                        @foreach ( var BannerID in Banners )
                        {
                            var Banner = Umbraco.TypedContent(BannerID);
                            if ( Banner != null )
                            {
                                @DisplaySlide(Banner, oneBanner, languageCode)
                            }
                        }
                    </div>
                </div>
            </div>
        }
    
    
    }
    
    @helper DisplaySlide(IPublishedContent Banner, bool oneBanner, string languageCode)
    {
    
    var imageId = Banner.GetPropertyValueAsInt("Image");
    IPublishedContent image = null;
    try
    {
        image = (imageId != null && imageId > 0) ? Umbraco.TypedMedia(imageId) : Umbraco.TypedMedia(DynConfig.Item("Site/DefaultImage/IdNoPhoto"));
    }
    catch (Exception ex)
    {
        Logger.Error(ex);
    }
    
    var color = Banner.GetPropertyValueAsString("textColor");
    var colorClass = "";
    switch ( color )
    {
        case "ffffff":
            colorClass = "white";
            break;
        case "000000":
            colorClass = "black";
            break;
    }
    
    var text = Banner.GetPropertyValueAsString(languageCode + "Text");
    
    var urlMulti = Banner.GetPropertyValue<MultiUrls>(languageCode + "Url");
    var url = "#";
    var target = "_self";
    
    if (urlMulti != null && urlMulti.Any())
    {
        url = urlMulti.FirstOrDefault().Url;
        target = urlMulti.FirstOrDefault().Target;
    }
    
        <div class="slide @colorClass">
            <a href="@url" target="@target" class="slide-link"></a>
            <div class="slide-content">
                <span class="slide-bg"></span>
    
                @if (oneBanner)
                {
                    <picture>
                        <!--[if IE 9]><video style="display: none;"><![endif]-->
                        <source srcset="@image.GetCropUrl(320, 180, quality:100), @image.GetCropUrl(640, 360, quality: 100) 1.5x" media="(max-width: 767px)">
                        <!--[if IE 9]></video><![endif]-->
                        <img class="bg-image" srcset="@image.GetCropUrl(1920, 480, quality: 100)" alt="image">
                    </picture>
                }
                else
                {
                    @GlobalHelpers.DisplayImage(image, 320, 180, 640, 360, 1060, 480, "bg-image")
                }
    
                @if (!String.IsNullOrEmpty(text))
                {
                    <strong class="active-title text-uppercase">@Html.Raw(text)</strong>
                    <strong class="inactive-title text-uppercase">@Html.Raw(text)</strong>
                }
    
            </div>
        </div>
    }
    

    Error happens in below particular code section:

    IPublishedContent image = null;
        try
        {
            image = (imageId != null && imageId > 0) ? Umbraco.TypedMedia(imageId) : Umbraco.TypedMedia(DynConfig.Item("Site/DefaultImage/IdNoPhoto"));
        }
        catch (Exception ex)
        {
            Logger.Error(ex);
        }
    
  • Nitesh 9 posts 89 karma points
    Dec 18, 2018 @ 11:29
    Nitesh
    0

    Any Updates Alex ?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Jan 02, 2019 @ 02:11
    Alex Skrypnyk
    0

    Hi Nitesh

    Did you solve this issue?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Dec 18, 2018 @ 11:51
    Alex Skrypnyk
    0

    Hi Nitesh

    What is in "DynConfig.Item("Site/DefaultImage/IdNoPhoto")" value?

  • Damien Holley 180 posts 541 karma points
    Jan 03, 2019 @ 04:11
    Damien Holley
    0

    Is the function returning an int or an int??

    If it does not return an int? then it cannot = null and you will get a syntax error.

    Have you tried testing the DynConfig with the parameter entered separate of this function?

  • Nitesh 9 posts 89 karma points
    Jan 03, 2019 @ 07:32
    Nitesh
    0

    Hi Alex and Damien,

    No, this issue still exists.

    The line >> DynConfig.Item("Site/DefaultImage/IdNoPhoto") returns an ID ( as a string type ) of a default image to use.

    I have cross checked and it doesn't returns any NULL, or Empty and Neither 0 [ Zero], but the correct ID of the image uploaded to Umbraco.

    Also, to add further, this issue occurs whenever we upload a new media and attach it to one of our page in CMS, and publish the page.

    In the logs shared above, there is this below line:

    Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetUmbracoMedia(Int32 id)
    

    Is thjere anything I also need to do for PublishedMediaCache ?

  • Damien Holley 180 posts 541 karma points
    Jan 03, 2019 @ 09:38
    Damien Holley
    0

    Ah, well maybe it's the cache has not been updated, I have come across a few cache issues in Umbraco.

    Is there any reason you are using DynConfig rather than getting the image from a root document or manually? I assume it is a placeholder when you do not have an image?

  • Nitesh 9 posts 89 karma points
    Jan 06, 2019 @ 09:29
    Nitesh
    0

    Hi Damien,

    Correct, DynConfig is used as a placeholder when an Image is not found.

    You mentioned yu have faced Cache issue in umbraco. So, Please let me know what steps you usually try to fix it ?

  • Damien Holley 180 posts 541 karma points
    Jan 07, 2019 @ 08:00
    Damien Holley
    100

    I avoid using anything that accesses cache or unmanaged (by user) variables like content numbers directly.

    So I would strongly recommend throwing anything to do with DynConfig in the rubbish. If you always have the image to use as a replacement in a certain area, then you could always access it directly ie: <img src="~/images/missingImage.png" />

    Typically if I hit a major cache issue and it is not me trying to access any cache directly, then I republish the entire site from the Umbraco backoffice, as this clears out the caches.

    In regards to avoiding the use of cache and one-time locations, for example if I was looking for a node in the base of my content tree I would use something like below:

    var root = Umbraco.TypedContentAtRoot().First(x=>x.DocumentTypeAlias == "[Document typename I am looking for]")
    

    it may be tempting to use var root = Umbraco.Content([node id]) but this means if you transfer any of this information to a different website, it will not work as the id numbers will be changed, whereas the method I have put in above will still work as the document type will not change in name.

Please Sign in or register to post replies

Write your reply to:

Draft