Copied to clipboard

Flag this post as spam?

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


  • Anuj 15 posts 35 karma points
    Feb 15, 2012 @ 09:00
    Anuj
    0

    GetMedia System.OverflowException: Value was either too large or too small for an Int32.

    Hi,

    I am new to umbraco and working on media files and getting some problems.Please have a look at them and tell  me where i am wrong.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:value-of select="$currentPage/mediaItem"/>   // Its returning 1052
     
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>
      // Here is the error.
    </xsl:template>

    </xsl:stylesheet>

    When i use   <xsl:value-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>

    then its throwing error

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    If i use  <xsl:value-of select="umbraco.library:GetMedia(1052, 'false')"/>

    Then its perfect.Please tell me whats wrong in the above code.

    Thanks


  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 15, 2012 @ 15:03
    Tom Fulton
    0

    Hi,

    You should wrap the GetMedia calls in a check to verify you have a value.  The reason is that when you press Save, Umbraco does a quick test of your XSLT file.  In this test it may not have a value for $currentPage/mediaItem - and this will cause an exception as GetMedia is expecting an integer.  Also this could happen if you run the macro on a page that doesn't have any media selected.

    So you can handle both situations by wrapping it in a test to ensure there is a value:

    <xsl:variable name="mediaId" select="$currentPage/mediaItem"/>

    <xsl:if test="$mediaId &gt; 0">
      <xsl:value-of select="umbraco.library:GetMedia($mediaId, false())"/>
    </xsl:if>

    Hope this helps,
    Tom

  • 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