Unity & HoloLens & MSBuild = [UNetWeaver] System.IndexOutOfRangeException:

Hi,

I have spent the entire weekend searching for solutions to this issue, and haven’t found anything that works. When I use an empty project, I get the same results. I am not using anything Photon related, or Unity Test Tools. Which have had issues previously with UNetWeaver/SerializationWeaver before previous Unity versions. I receive the same error if the project is on my C: drive.

When I use MSBuild from VS 2017 or VS 2015 with Update 3, the build fails when building the Assembly-CSharp-firstpass project with an error from the SerializationWeaver saying:

EXEC : UNetWeaver error : Exception :System.IndexOutOfRangeException: Index was outside the bounds of the array
[Full details at bottom of post.]

If I use Visual Studio to build the solution, it builds successfully. Also if I use Visual Studio to build Appx store packages, it is successful.

The goal is not to use Visual Studio at all, and use MSBuild so this process can be completely automated with Jenkins.

I am working on a Microsoft HoloLens project in Unity 5.6.0f3 on Windows 10 Pro.

I have built a VS SLN multiple ways:

  1. From Unity using the standard build window: File->Build Settings
  2. From Unity using HoloToolKit
  3. Using the command line, calling a custom build script

The solution is always generated successfully with 3 projects. MyProject, Assembly-CSharp, and Assembly-CSharp-firstpass.

My goal is to create a MSBuild command call, to be used by Jenkins to Automate my build process. I already have a Unity script to generate the solution.

The error persists with multiple combinations of

x86 / x64 / ARM
Debug / Release / Master
Clean / Build / Rebuild

Please let me know if you require any more information, and I will get back to you.

Thanks in advance!


The Full Detailed Error Message:
RunSerializationWeaver:
Running SerializationWeaver…
Moving file from “obj\ARM\Debug\ARM\Debug\Assembly-CSharp-firstpass.dll” to “D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assembly-CSharp-firstpass.dll”.
Moving file from “obj\ARM\Debug\ARM\Debug\Assembly-CSharp-firstpass.pdb” to “D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assembly-CSharp-firstpass.pdb”.
“D:\Unity\App\Unity\Tools\SerializationWeaver\SerializationWeaver.exe” “D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assem
bly-CSharp-firstpass.dll” -pdb -verbose -unity-engine=“D:\Unity\App\MyProject\Unprocessed\UnityEngine.dll” -unity-networking=“D:\Unity\App\MyProject\Unprocessed\UnityEn
gine.Networking.dll” “D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\obj\ARM\Debug\ARM\Debug”
Symbols will be read from D:\Unity\App\MyProject\Unprocessed\UnityEngine.pdb
Symbols will be read from D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assembly-CSharp-firstpass.pdb
WeaveAssemblies unityPath= D:\Unity\App\MyProject\Unprocessed\UnityEngine.dll
WeaveAssemblies unetPath= D:\Unity\App\MyProject\Unprocessed\UnityEngine.Networking.dll
Symbols will be read from D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assembly-CSharp-firstpass.pdb
System.Exception: Failed to generate networking code for D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\bin\ARM\Debug\Unprocessed\Assembly-CSharp-firstpass.dll:
EXEC : UNetWeaver error : Exception :System.IndexOutOfRangeException: Index was outside the bounds of the array. [D:\Unity\App\GeneratedProjects\UWP\Assembly-CSharp-firstpass\Assembly-CSharp-firstpass.
csproj]
at Mono.Cecil.Mixin.ParseRuntime(String self)
at Mono.Cecil.ModuleDefinition…ctor(Image image)
at Mono.Cecil.ModuleReader.CreateModuleReader(Image image, ReadingMode mode)
at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Unity.UNetWeaver.Weaver.Weave(String assName, IEnumerable1 dependencies, IAssemblyResolver assemblyResolver, String unityEngineDLLPath, String unityUNetDLLPath, String outputDir) at Unity.UNetWeaver.Weaver.WeaveAssemblies(IEnumerable1 assemblies, IEnumerable`1 dependencies, IAssemblyResolver assemblyResolver, String outputDir, String unityEngineDLLPath, String unityUNetDLLPath)
at usw.Weaver.Weave()
at usw.Program.RunProgram(ConversionOptions options)
at usw.Program.Main(String[ ] args)

I discovered that Visual Studio has Update Nuget Packages automatically when projects are being built. The project Assembly-CSharp-firstpass needs NetCore updated (It is 5.0.0, and I updated it to 5.3.3) After the update has been done, MSBuild works successfully.