Exemple #1
0
        public override Object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
        {
            if (absoluteUri == null)
            {
                throw new ArgumentNullException(nameof(absoluteUri));
            }

            if (s_appStreamResolver == null)
            {
                Debug.Assert(false, "No IApplicationResourceStreamResolver is registered on the XmlXapResolver.");
                throw new XmlException(SR.Xml_InternalError, string.Empty);
            }

            if (ofObjectToReturn == null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(Object))
            {
                // Note that even though the parameter is called absoluteUri we will only accept
                //   relative Uris here. The base class's ResolveUri can create a relative uri
                //   if no baseUri is specified.
                // Check the argument for common schemes (http, file) and throw exception with nice error message.
                Stream stream;
                try {
                    stream = s_appStreamResolver.GetApplicationResourceStream(absoluteUri);
                }
                catch (ArgumentException e) {
                    throw new XmlException(SR.Xml_XapResolverCannotOpenUri, absoluteUri.ToString(), e, null);
                }
                if (stream == null)
                {
                    throw new XmlException(SR.Xml_CannotFindFileInXapPackage, absoluteUri.ToString());
                }
                return(stream);
            }
            else
            {
                throw new XmlException(SR.Xml_UnsupportedClass, string.Empty);
            }
        }