Unhandled exception: BadImageFormatException: Bad IL format. The format of the file 'XXXModuleRules.dll' is invalid.

When I try to create a blank C++ project I got the following error:

Unhandled exception: BadImageFormatException: Bad IL format. The format of the file ‘C:\work\Unreal Projects\QuickStart\Intermediate\Build\BuildRules\QuickStartModuleRules.dll’ is invalid.

Seems like a problem with .Net. To be sure that the right .Net versions are installed I consulted
Unreal Engine 5.5 Release Notes | Unreal Engine 5.5 Documentation | Epic Developer Community
and found the following:

  • .NET 4.6.2 Targeting Pack
  • .NET 8.0
    I installed just that on my machine and removed other .Net versions but still get the same failure.
    The exact failure from the console:

Running C:/Program Files/Epic Games/UE_5.5/Engine/Build/BatchFiles/Build.bat -projectfiles -project=“C:/work/Unreal Projects/QuickStart/QuickStart.uproject” -game -rocket -progress
Using bundled DotNet SDK version: 8.0.300
Running UnrealBuildTool: dotnet “....\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll” -projectfiles -project=“C:/work/Unreal Projects/QuickStart/QuickStart.uproject” -game -rocket -progress
Log file: C:\Users\XXX\AppData\Local\UnrealBuildTool\Log_GPF.txt

Generating VisualStudio project files:
Discovering modules, targets and source code for project…
Available x64 toolchains (1):

  • C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.43.34808
    (Family=14.43.34808, FamilyRank=1, Version=14.43.34810, Is64Bit=True, ReleaseChannel=Latest, Architecture=x64)
    Visual Studio 2022 compiler version 14.43.34810 is not a preferred version. Please use the latest preferred version 14.38.33130
    Total execution time: 1.32 seconds
    Unhandled exception: BadImageFormatException: Bad IL format. The format of the file ‘C:\work\Unreal Projects\QuickStart\Intermediate\Build\BuildRules\QuickStartModuleRules.dll’ is invalid.
    at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
    at System.Reflection.Assembly.LoadFile(String path)
    at UnrealBuildTool.DynamicCompilation.CompileAssembly(FileReference OutputAssemblyPath, IEnumerable1 SourceFileNames, ILogger Logger, IEnumerable1 ReferencedAssembies, IEnumerable1 PreprocessorDefines, Boolean TreatWarningsAsErrors) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\DynamicCompilation.cs:line 289 at UnrealBuildTool.DynamicCompilation.CompileAndLoadAssembly(FileReference OutputAssemblyPath, IEnumerable1 SourceFileNames, ILogger Logger, IEnumerable1 ReferencedAssembies, IEnumerable1 PreprocessorDefines, Boolean DoNotCompile, Boolean ForceCompile, Boolean TreatWarningsAsErrors) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\DynamicCompilation.cs:line 351
    at UnrealBuildTool.RulesAssembly..ctor(RulesScope Scope, IReadOnlyList1 BaseDirs, IReadOnlyList1 Plugins, IReadOnlyDictionary2 ModuleFileToContext, IReadOnlyList1 TargetFiles, FileReference AssemblyFileName, Boolean bContainsEngineModules, Nullable1 DefaultBuildSettings, Boolean bReadOnly, Boolean bSkipCompile, Boolean bForceCompile, RulesAssembly Parent, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:line 191 at UnrealBuildTool.RulesCompiler.<>c__DisplayClass9_0.<CreateProjectRulesAssembly>b__0(FileReference _) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesCompiler.cs:line 332 at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at UnrealBuildTool.RulesCompiler.CreateProjectRulesAssembly(FileReference ProjectFileName, Boolean bUsePrecompiled, Boolean bSkipCompile, Boolean bForceCompile, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesCompiler.cs:line 247 at UnrealBuildTool.ProjectFileGenerator.AddProjectsForAllTargets(PlatformProjectGeneratorCollection PlatformProjectGenerators, List1 AllGames, List1 AllTargetFiles, String[] Arguments, List1 EngineProjects, List1 GameProjects, Dictionary2 ProjectFileToUProjectFile, Dictionary2 ProgramProjects, Dictionary2 RulesAssemblies, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 2791
    at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String Arguments, Boolean bCacheDataForEditor, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1048
    at UnrealBuildTool.GenerateProjectFilesMode.ExecuteAsync(CommandLineArguments Arguments, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 260
    at UnrealBuildTool.UnrealBuildTool.Main(String ArgumentsArray) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 687

Can anyone help me with this issue?

Thank you very much

Hello there @tsi6800!

You are on the right track. Your updated log after the .Net installs has the following call:

Visual Studio 2022 compiler version 14.43.34810 is not a preferred version. Please use the latest preferred version 14.38.33130

This means that your current Visual Studio build is either missing components, or its using invalid ones. You can follow the installation guide from the community, which can be found here:

Additionally, another thread has a detailed explanation for the compiler setup, please follow the steps included:

Hello brs-sebascova

Thank you for your quick reply. Following your advice I could remove the warning

Visual Studio 2022 compiler version 14.43.34810 is not a preferred version. Please use the latest preferred version 14.38.33130

by selecting this version in the Visual Studio Installer

I also follow the installation instructions from

Setting Up Visual Studio Development Environment for C++ Projects in Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

and install the designated versions MSVC, Windows SDK, LLVM, .Net, added the required workloads and added the required components

I also updated the BuildConfiguration.xml under C:\Users\XXX\AppData\Roaming\Unreal Engine\UnrealBuildTool as suggested in

Packaging error ‘detected compiler newer than visual studio 2022’ - beginner - Development / Programming & Scripting - Epic Developer Community Forums

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
<WindowsPlatform>
<CompilerVersion>14.38.33130</CompilerVersion>
<ToolchainVersion>14.38.33130</ToolchainVersion>
</WindowsPlatform>
</Configuration>

I restarted my system to be sure that all packages are loaded fresh but nevertheless when I want to create a new blank C++ Project in Unreal I still got the BadImageFormatException.

The recent log looks like that:

Running C:/Program Files/Epic Games/UE_5.5/Engine/Build/BatchFiles/Build.bat -projectfiles -project=“C:/work/Unreal Projects/QuickStart/QuickStart.uproject” -game -rocket -progress
Using bundled DotNet SDK version: 8.0.300
Running UnrealBuildTool: dotnet “....\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll” -projectfiles -project=“C:/work/Unreal Projects/QuickStart/QuickStart.uproject” -game -rocket -progress
Log file: C:\Users\XXX\AppData\Local\UnrealBuildTool\Log_GPF.txt

Generating VisualStudio project files:
Discovering modules, targets and source code for project…
Total execution time: 1.38 seconds
Unhandled exception: BadImageFormatException: Bad IL format. The format of the file ‘C:\work\Unreal Projects\QuickStart\Intermediate\Build\BuildRules\QuickStartModuleRules.dll’ is invalid.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFile(String path)
at UnrealBuildTool.DynamicCompilation.CompileAssembly(FileReference OutputAssemblyPath, IEnumerable1 SourceFileNames, ILogger Logger, IEnumerable1 ReferencedAssembies, IEnumerable1 PreprocessorDefines, Boolean TreatWarningsAsErrors) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\DynamicCompilation.cs:line 289 at UnrealBuildTool.DynamicCompilation.CompileAndLoadAssembly(FileReference OutputAssemblyPath, IEnumerable1 SourceFileNames, ILogger Logger, IEnumerable1 ReferencedAssembies, IEnumerable1 PreprocessorDefines, Boolean DoNotCompile, Boolean ForceCompile, Boolean TreatWarningsAsErrors) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\DynamicCompilation.cs:line 351
at UnrealBuildTool.RulesAssembly..ctor(RulesScope Scope, IReadOnlyList1 BaseDirs, IReadOnlyList1 Plugins, IReadOnlyDictionary2 ModuleFileToContext, IReadOnlyList1 TargetFiles, FileReference AssemblyFileName, Boolean bContainsEngineModules, Nullable1 DefaultBuildSettings, Boolean bReadOnly, Boolean bSkipCompile, Boolean bForceCompile, RulesAssembly Parent, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:line 191 at UnrealBuildTool.RulesCompiler.<>c__DisplayClass9_0.<CreateProjectRulesAssembly>b__0(FileReference _) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesCompiler.cs:line 332 at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at UnrealBuildTool.RulesCompiler.CreateProjectRulesAssembly(FileReference ProjectFileName, Boolean bUsePrecompiled, Boolean bSkipCompile, Boolean bForceCompile, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\RulesCompiler.cs:line 247 at UnrealBuildTool.ProjectFileGenerator.AddProjectsForAllTargets(PlatformProjectGeneratorCollection PlatformProjectGenerators, List1 AllGames, List1 AllTargetFiles, String[] Arguments, List1 EngineProjects, List1 GameProjects, Dictionary2 ProjectFileToUProjectFile, Dictionary2 ProgramProjects, Dictionary2 RulesAssemblies, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 2791
at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String Arguments, Boolean bCacheDataForEditor, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1048
at UnrealBuildTool.GenerateProjectFilesMode.ExecuteAsync(CommandLineArguments Arguments, ILogger Logger) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 260
at UnrealBuildTool.UnrealBuildTool.Main(String ArgumentsArray) in D:\build++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 687

For me the setup looks like suggested, do you have another hint for me?

I would appreciate that a lot.

Thanks

Hello again!

That’s good, the compiler error is gone, now we just need to sort out “BadImageFormatException”. Since the error call aims at QuickStartModuleRules.dll, the process is most likely clashing with with corrupt or missing elements tied to .NET assembly.

As first approach, please test deleting the Intermediate and Binaries folders, then regenerate the project files. If the issue remains active after that, delete the DerivedDataCache, and repeat the process.

Alternatively, since you are currently working with .NET 8.0.300, it would be worth a shot downgrading to .NET 6.0, which is currently the recommended version for UE5 (Download .NET 6.0 (Linux, macOS, and Windows) | .NET).