public async Task <Message> ProvideAsync(IFileValidationContext fileValidationContext, CancellationToken cancellationToken)
        {
            using (var stream = await _fileService.OpenReadStreamAsync(fileValidationContext.FileReference, fileValidationContext.Container, cancellationToken))
            {
                _xsdValidationService.Validate(stream);

                stream.Position = 0;

                return(_xmlSerializationService.Deserialize <Message>(stream));
            }
        }
        private bool ValidateSchema(Stream sourceFileStream)
        {
            // Ensure we are at the start of the stream
            sourceFileStream.Seek(0, SeekOrigin.Begin);

            XmlSchema    schema       = _xmlSchemaProvider.Provide();
            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();

            xmlSchemaSet.Add(schema);
            xmlSchemaSet.Compile();
            _xsdValidationService.ValidateNamespace(sourceFileStream, xmlSchemaSet, RetrieveRootElement(schema), _validationErrorHandler.XsdNsValidationErrorHandler);
            _xsdValidationService.Validate(sourceFileStream, xmlSchemaSet, _validationErrorHandler.XsdValidationErrorHandler);
            return(true);
        }