Why am I getting the Compile Error: UnrealBuildTool?

I am receiving the following error. I am running Visual Studio 2013 Professional on Windows7 64bit.

EXEC : error : System.ArgumentOutOfRangeException: Length cannot be less than zero.
28> Parameter name: length
28> at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
28> at UnrealBuildTool.Utils.SetEnvironmentVariablesFromBatchFile(String BatchFileName) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\Utils.cs:line 316
28> at UnrealBuildTool.VCToolChain.InitializeEnvironmentVariables(CPPTargetPlatform Platform) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Windows\VCToolChain.cs:line 1428
28> at UnrealBuildTool.VCToolChain.GetVCToolPath(CPPTargetPlatform Platform, CPPTargetConfiguration Configuration, String ToolName) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Windows\VCToolChain.cs:line 1308
28> at UnrealBuildTool.VCToolChain.CompileCPPFiles(CPPEnvironment CompileEnvironment, List1 SourceFiles, String ModuleName) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Windows\VCToolChain.cs:line 897 28> at UnrealBuildTool.CPPEnvironment.CompileFiles(List1 CPPFiles, String ModuleName) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\CPPEnvironment.cs:line 283
28> at UnrealBuildTool.PrecompileHeaderEnvironment.GeneratePCHCreationAction(String PCHHeaderNameInCode, FileItem PrecompiledHeaderIncludeFilename, CPPEnvironment ProjectCPPEnvironment, String OutputDirectory, String ModuleName, Boolean bAllowDLLExports) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\Utils.cs:line 100
28> at UnrealBuildTool.UEBuildModuleCPP.Compile(CPPEnvironment GlobalCompileEnvironment, CPPEnvironment CompileEnvironment, Boolean bCompileMonolithic) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildModule.cs:line 1390
28> at UnrealBuildTool.UEBuildBinaryCPP.Build(CPPEnvironment CompileEnvironment, LinkEnvironment LinkEnvironment) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildBinary.cs:line 474
28> at UnrealBuildTool.UEBuildTarget.Build() in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 1333
28> at UnrealBuildTool.UnrealBuildTool.RunUBT(String Arguments) in c:\Users\buad\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\UnrealBuildTool.cs:line 1040

Hi buad,

Apologies for the delayed response. Is this occurring when you first compile the unmodified Source code from GitHub? Or are you compiling code you have written? What Solution Configurations are you building with?

Thanks

I believe the issue was a result of multiple VS installations. I did a clean install of win 8.1 and everything is now working well. Thanks for the reply.

Can someone confirm this, or figure out what is causing this error, so I can take a value out of the registry or something ? I have the same / similar issues :

For me I’ve never built Unreal on this box before, and I did see old installs of VS 11 and VS 8 but they don’t seem to be installed or at least not in the path, the way I found out was to see empty folders in the start menu.

Setting up Unreal Engine 4 project files…
Binding IntelliSense data… 100%
Writing project files… 0%
UnrealBuildTool Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at UnrealBuildTool.Utils.SetEnvironmentVariablesFromBatchFile(String BatchFileName) in e:\Perforce\dcrosby_MAYBACH_Unreal4.6\UnrealEngine-4.6\Engine\Source\Programs\UnrealBuildTool\System\Utils.cs:line 231

UnrealBuildTool.UnrealBuildTool.GenerateProjectFiles(ProjectFileGenerator Generator, String[] Arguments) in e:\Perforce\dcrosby_MAYBACH_Unreal4.6\UnrealEngine-4.6\Engine\Source\Programs\UnrealBuildTool\System\UnrealBuildTool.cs:line 1196
at UnrealBuildTool.UnrealBuildTool.Main(String[] Arguments) in e:\Perforce\dcrosby_MAYBACH_Unreal4.6\UnrealEngine-4.6\Engine\Source\Programs\UnrealBuildTool\System\UnrealBuildTool.cs:line 1042

GenerateProjectFiles ERROR: UnrealBuildTool was unable to generate project files.

Press any key to continue . . .

Hey DCrosby-

The original issue seems it was fixed with a fresh install of VS. Have you tried removing all versions of VS (11, 8, and 13 if you have it) and then doing a fresh install of VS13 Express? Express is a free version of VS that is fully compatible with UE4.

Cheers