none
System.ArgumentOutOfRangeException thrown by GlyphTypeface constructor when URI>112 characters

    Question

  • I work with an application that needs to work with somewhat long paths. The problem is that the GlyphTypeface throws an exception when I try to call its constructor with an absolute Uri including more than 112 characters. Here is a simple application that generates the problem:

    Uri uri = new Uri(@"C:\1234567890\1234567890\1234567890\1234567890\1234567890\1234567890\1234567890\1234567890\123456789\FontFile.ttf", UriKind.Absolute);
    GlyphTypeface glyphTypeface = new GlyphTypeface(uri);

    The "new GlyphType(uri)" generates to following line:

    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in PresentationCore.dll

    I've looked around trying to find more information about the problem, but could not find any. Note that the glyphTypeface is still functional once the exception has been thrown. I'd like to know how to get rid of this exception.

    Fred

    Tuesday, December 16, 2008 3:16 PM

All replies

  • This bug is really annoying. My system is throwing a lot of exception and I have no way of controlling it.

    All help appreciated.

    Fred
    Wednesday, December 17, 2008 2:14 PM
  • Can you make Uri shorter when design?
    • Marked as answer by Tao Liang Monday, December 22, 2008 1:48 AM
    • Unmarked as answer by fredx21 Monday, December 22, 2008 1:49 AM
    Friday, December 19, 2008 4:05 AM
  • Unfortunately the URIs are automatically generated for specific reason and cannot be changed.

    Is the 112 characters limit a bug?

    I'm using .net 3.5 SP1 runtimes.

    Fred
    Friday, December 19, 2008 6:37 AM
  •  

    When we use the constructor of  GlyphTypeface, Initialize method was applied.:

    [SecurityCritical]
    private void Initialize(Uri typefaceSource, StyleSimulations styleSimulations, bool fromPublic)
    {
        Uri uri;
        int num;
        if (typefaceSource == null)
        {
            throw new ArgumentNullException("typefaceSource");
        }
        if (!typefaceSource.IsAbsoluteUri)
        {
            throw new ArgumentException(SR.Get("UriNotAbsolute"), "typefaceSource");
        }
        this._originalUri = new SecurityCriticalDataClass<Uri>(typefaceSource);
        Util.SplitFontFaceIndex(typefaceSource, out uri, out num);
        this._fileIOPermObj = new SecurityCriticalDataForSet<CodeAccessPermission>(SecurityHelper.CreateUriReadPermission(uri));
        if (fromPublic)
        {
            this.DemandPermissionsForFontInformation();
        }
        this._fontFace = new FontFaceLayoutInfo(new FontSource(uri, true), num);
        CacheManager.Lookup(this._fontFace);
        if ((styleSimulations & ~StyleSimulations.BoldItalicSimulation) != StyleSimulations.None)
        {
            throw new InvalidEnumArgumentException("styleSimulations", (int) styleSimulations, typeof(StyleSimulations));
        }
        this._styleSimulations = styleSimulations;
        this._initializationState = InitializationState.IsInitialized;
    }
    ////

    The Uri ( named "typefaceSource" ) will be spilted.
    Util.SplitFontFaceIndex(typefaceSource, out uri, out num);

    The code of split is:

    internal static void SplitFontFaceIndex(Uri fontUri, out Uri fontSourceUri, out int faceIndex)
    {
        string components = fontUri.GetComponents(UriComponents.Fragment, UriFormat.SafeUnescaped);
        if (!string.IsNullOrEmpty(components))
        {
            if (!int.TryParse(components, NumberStyles.None, CultureInfo.InvariantCulture, out faceIndex))
            {
                throw new ArgumentException(SR.Get("FaceIndexMustBePositiveOrZero"), "fontUri");
            }
            fontSourceUri = new Uri(fontUri.GetComponents(UriComponents.HttpRequestUrl | UriComponents.UserInfo, UriFormat.SafeUnescaped));
        }
        else
        {
            faceIndex = 0;
            fontSourceUri = fontUri;
        }
    }

    This code of getting the Components of a Uri:
    string components = fontUri.GetComponents(UriComponents.Fragment, UriFormat.SafeUnescaped);

    ////
    public string GetComponents(UriComponents components, UriFormat format)
    {
        if (((components & UriComponents.SerializationInfoString) != 0) && (components != UriComponents.SerializationInfoString))
        {
            throw new ArgumentOutOfRangeException("UriComponents.SerializationInfoString");
        }
        if ((format & ~UriFormat.SafeUnescaped) != ((UriFormat) 0))
        {
            throw new ArgumentOutOfRangeException("format");
        }
        if (this.IsNotAbsoluteUri)
        {
            if (components != UriComponents.SerializationInfoString)
            {
                throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
            }
            return this.GetRelativeSerializationString(format);
        }
        if (this.Syntax.IsSimple)
        {
            return this.GetComponentsHelper(components, format);
        }
        return this.Syntax.InternalGetComponents(this, components, format);
    }

    It looks like the format of Uri is not very proper (too long for GlyphTypeface).






     




     



    Friday, December 19, 2008 7:54 AM
  • I tried calling directly

      string component = uri.GetComponents(UriComponents.Fragment, UriFormat.SafeUnescaped)

    But it did not throw any exception. Howerver, I made a few more tests and I've got a bit more info about the error:

      A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in PresentationCore.dll

      Additional information: Specified argument was out of the range of valid values.

      Step into: Stepping over method without symbols 'MS.Internal.FontCache.IPCCacheManager.SendMissReport'
      Step into: Stepping over method without symbols 'MS.Internal.FontCache.CacheManager.Lookup'
      Step into: Stepping over method without symbols 'System.Windows.Media.GlyphTypeface.Initialize'

    The problem seems to happen in CacheManager.Lookup(). I hope this can help you finding the source of the problem.

    Fred
    Friday, December 19, 2008 6:47 PM
  • Any updates on this issue? Is it a bug?
    Monday, January 12, 2009 3:20 PM
  • Yes, I think so.

    I can reproduce the issue with your steps and I have to admit that the behavior is less desirable.

    You can report this issue at:
    Feedback


    Wednesday, January 14, 2009 3:39 AM