The custom action that implements RemoveFolderEx does so by writing temporary rows to the RemoveFile table for each subfolder of the root folder you specify. Because it might dramatically affect Windows Installer's [File Costing](https://learn.microsoft.com/en-us/windows/win32/msi/file-costing), the temporary rows must be written before the CostInitialize standard action. Unfortunately, MSI doesn't create properties for the Directory hierarchy in your package until later, in the CostFinalize action.
An easy workaround for a typical use case of removing a folder during uninstall is to write the directory path to the registry and to load it during uninstall. See [The WiX toolset's "Remember Property" pattern](http://robmensching.com/blog/posts/2010/5/2/the-wix-toolsets-remember-property-pattern) for an example.
If you use custom actions to set properties, ensure that they are scheduled before the WixRemoveFoldersEx custom action.