🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Solved – InvalidArgumentException Error in Magento 2.3.5

By Sanjay JethvaUpdated on Jul 17, 2025 3 min read

Magento is one of the most preferred platforms for creating E-commerce stores. And that is for a reason!

The platform powered by Adobe keeps on releasing new versions frequently to stay up to date with the latest technology and increasing business demands.

It is recommended that merchants migrate their Magento 2 stores to the latest version Magento 2.4.8 in order to avail the performance and security benefits.

However, while installing Magento 2.3.5 or its above versions, you may face an error that says,

Unable to apply data patch MagentoThemeSetupPatchDataRegisterThemes for module Magento_Theme. Original exception message: Wrong file

Today, I will be talking about the solution for solving the error InvalidArgumentException error in Magento 2.3.5 or above version.

Solution for InvalidArgumentException Error in Magento 2.3.5 in Gd2.php:64

The below image shows the error that occurs while installing Magento 2.3.5.

The command prompt shows the line 64. However, if you open the file in edit mode, you need to make changes in it at line 96.

Solution for InvalidArgumentException Error in Magento 2

Open vendor\magento\framework\Image\Adapter\Gd2.php.

At line 96, replace:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) {
          return false;
      }

      return true;
  }

With the below code:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) 
{
          return false;
      }

      return true;
  }

All you have to do is to replace the below string:

 if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes

With:

if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename))

That’s it.

Do consider sharing this post with the Magento community via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.