Getting an unusual error on project recompile

I started a brand new code project on UE5 and it compiled fine. But whenever I try to recompile it, I get the following error (in VS):

Unhandled exception: Dependency file “D:\Unreal\Projects\Prasads\TROAV\Intermediate\Build\Win64\TROAVEditor\Development\Engine\SharedPCH.Engine.ShadowErrors.h.json” version (“1.2”) is not supported version

The only solution is to clean the project and recompile the whole thing again.

I’m using VS 2022.

2 Likes

have you repaired and checked that you have the correct Game Dev plugins for VS in the VSInstaller?

which plugins? it seems only unreal launcher installer and Unreal Android IDE support here

It’s not about Game Dev plugins at all.

UE5 uses a build system which depends on generated json files (I guess it’s a build system optimization). By default, VS2022 generates these json files with the version parameter set to 1.2. The UE build system, however, expects that version number to be 1.1 or lower. Hence we get the error on a recompile. It goes away on a clean build because these json files are cleaned away.

The actual fix lies in fixing the source, however, for everyone using the launcher version, the easy way to hack around this is to put the following snippet of code:

// Workaround for the .cpp.json version bug. Essentially, with VS 2022’s latest compiler, the
// .cpp.json files Unreal needs get written in with Version = 1.2. This needs to be 1.1 (or lower)
namespace Workarounds
{
using System;
using System.IO;

public class BuildVersionWorkaround
{
    // For testing only
    private static void Main()
    {
        var currentDir = Environment.CurrentDirectory;
        SearchFiles(currentDir);
    }

    public static void ExecuteWorkaround(string path)
    {
        var rootDirectory = Path.GetDirectoryName(path);

        Console.WriteLine($"Module path => {rootDirectory}");

        var targetFixDirectory = Path.Combine(rootDirectory, "Intermediate", "Build");

        Console.WriteLine($"Fix target path => {targetFixDirectory}");

        SearchFiles(targetFixDirectory);

        var pluginFixDirectory = Path.Combine(rootDirectory, "Plugins");

        DirectoryInfo pluginInfo = new DirectoryInfo(pluginFixDirectory);
        if (pluginInfo.Exists)
        {
            DirectoryInfo[] plugs = pluginInfo.GetDirectories();

            foreach (DirectoryInfo pl in plugs)
            {
                var plgDir = Path.Combine(pluginFixDirectory, pl.Name, "Intermediate", "Build");
                Console.WriteLine($"Fix plugin path => {plgDir}");
                SearchFiles(plgDir);
            }
        }

        Console.WriteLine($"Everything Done");
    }

    const string FilterName = "*.json";
    private static void SearchFiles(string path)
    {
        var info = new DirectoryInfo(path);

        var files = info.GetFiles(FilterName);

        foreach (var file in files)
        {
            using var filestream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            FixFile(filestream);
        }

        var directories = info.GetDirectories();

        foreach (var directory in directories)
        {
            SearchFiles(directory.FullName);
        }
    }

    const string OriginPattern = "\"Version\": \"1.2\",";
    const string TargetPattern = "\"Version\": \"1.1\",";
    private static void FixFile(FileStream FileStream)
    {
        using var reader = new StreamReader(FileStream);

        // Not the optimal way but probably good enough.
        var text = reader.ReadToEnd();
        if (text.Contains(OriginPattern))
        {
            Console.WriteLine($"Fixing => {FileStream.Name}");
            text = text.Replace(OriginPattern, TargetPattern);

            // Restart file position
            FileStream.Position = 0;

            using var writer = new StreamWriter(FileStream);
            writer.Write(text);
            writer.Flush();

            // Arrays start at 0 but sizes doesn't
            var newSize = FileStream.Position + 1;

            if (newSize != FileStream.Length)
            {
                FileStream.SetLength(newSize);
            }

            FileStream.Flush();
        }
    }
}

}

into your ProjectName.Build.cs file, after the project modulerules class.

And then in the constructor of the modulerules class, call the following snippet:

// Calling workaround to fix versions in jsons (long story; i know)
Workarounds.BuildVersionWorkaround.ExecuteWorkaround(Target.ProjectFile.ToNormalizedPath());

This should fix this error.

1 Like