.NET scripting backend and Visual Studio 2017.3 incompatibility

Hi,

we very recently discovered that there is a compatibility issue between Unity and upcoming Visual Studio 2017 update 3 when targeting UWP, using .NET scripting backend (IL2CPP scripting backend is not affected) and building generated Visual Studio project. It shows itself as this exception in the output window:

1>------ Build started: Project: AppTest, Configuration: Debug x86 ------
1>  AppTest -> D:\AppTest\AppTest\bin\x86\Debug\AppTest.exe
1>  UnityWSAPlayerDir "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\".
1>  UnityProjectDir "".
1>  Copying unprocessed assemblies...
1>  Running AssemblyConverter...
1>  System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
1>     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
1>     at UnityEditor.Scripting.Compilers.NuGetPackageResolver.Resolve()
1>     at Unity.UWPAssemblyResolver..ctor(String projectLockFile, String desiredUWPSDKVersion)
1>     at Unity.OperationContext.SetPlatform(Platform platform, String projectLockFile, String uwpSDK)
1>     at Unity.ParseArgsStep.Execute()
1>     at Unity.Step.Execute(OperationContext operationContext, IStepContext previousStepContext)
1>     at Unity.Operation.Execute()
1>     at Unity.Program.Main(String[] args)
1>D:\AppTest\AppTest\AppTest.csproj(257,9): error MSB3073: The command ""D:\AppTest\Unity\Tools\AssemblyConverter.exe" -platform=uap -lock="D:\AppTest\AppTest\project.lock.json" -bits=32 -configuration=Debug -removeDebuggableAttribute=False -uwpsdk=10.0.15063.0 -path="." -path="C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Players\UAP\dotnet\x86\Debug" "D:\AppTest\AppTest\UnityEngine.dll" "D:\AppTest\AppTest\UnityEngine.Analytics.dll" "D:\AppTest\AppTest\nunit.framework.dll" "D:\AppTest\AppTest\UnityEngine.UI.dll" "D:\AppTest\AppTest\UnityEngine.Networking.dll"" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

We will soon be releasing patch releases to fix that, backporting it all the way to Unity 5.5 (which was the first release to even support VS 2017 when building for UWP). Until then, if you’re targeting UWP and using .NET scripting backend, we suggest refraining from upgrading to Visual Studio 2017.3 (which got released on August 14th).

Here is the status of patches with the fix:

5.5 version with the fix: 5.5.4p5
5.6 version with the fix: 5.6.3p2
2017.1 version with fix: 2017.1.0p5
2017.2 version with fix: 2017.2.0b7

6 Likes

Noooooooooooooo!!! My VS2017 got upgraded automatically because I had to install a new component… Does anyone know how to downgrade to version 15.2? I don’t mind uninstalling the entire thing and reinstalling… but I cant seem to find an installer for the specific 15.2 version

Can’t believe my luck :frowning:

Ok… think I finally found the VS2017 v15.0 downloads… they are available on my.visualstudio.com and you need to sign in to get access to the .exes:

Enterprise Edition: Azure DevOps Services | Sign In
Community Edition: Azure DevOps Services | Sign In
Professional Edition: Azure DevOps Services | Sign In

See you in 5 hours as I uninstall and reinstall VS :frowning: :frowning: :frowning:

2 Likes

Yeah, sorry you ran into this. Workarounds (other than reinstalling VS2017 from scratch) involve using VS2015 to build the generated project, using IL2CPP temporarily (unless your project doesn’t build with it) or using this trick a person on HoloLens forums found.

1 Like

All fixed on downgrading! Thanks!

Just my luck, this issue hit me like a ton of bricks right before an important demo on Friday, when my VS2017 did an update when I didn’t mean to (I just wanted to see what components were installed but it wouldn’t let me until I updated it). I spent all day trying to install VS2017 and Unity 2017.2.0b8 on other build systems, only to find they all had this same error. Well now I know what I need to do when I get back to work next week. Thanks for the confirmation, though! It puts my mind at ease this weekend. :slight_smile:

I am facing the same issue, did it work for you ?

@saurabh_cv I haven’t tried it yet. However, it looks like @ei2kpi provided the links needed to backtrack VS2017 to version 15.0 to workaround the issue for now. Unfortunately, the downside is that it will require an uninstall/re-install of VS2017 which will set you back about an hour or two (and a keen eye to make sure that it doesn’t attempt to update itself again).

Hi all,

No need to downgrade Visual Studio. One way to eliminate the problem is to edit the “project.lock.json” file and replace each occurrence of “UAP,Version=v10.0.10240” with “UAP,Version=v10.0”. Note that each time you rebuild the VS project the “project.lock.json” file will be recreated and you will need to redo the edit.

For your convenience, you may develop a quick tool to do the edit. I have created a console application and all I need now is to copy the EXE file next to the “project.lock.json” file and run the EXE each time I need to do the edit. The source code for the console application is:

namespace FixVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string content = string.Empty;
                using (StreamReader reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\project.lock.json"))
                {
                    content = reader.ReadToEnd();
                    content = content.Replace("UAP,Version=v10.0.10240", "UAP,Version=v10.0");
                    reader.Close();
                }

                using (StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\project.lock.json"))
                {
                    writer.Write(content);
                    writer.Close();
                }

                Console.WriteLine("DONE.");
            }
            catch(Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Good luck :slight_smile:

6 Likes

I run into this when building the project to deploy after patching assemblies stage 2 with 2017.2.0b8:

KeyNotFoundException: The given key was not present in the dictionary.
System.ThrowHelper.ThrowKeyNotFoundException () (at <9c9f068c46c64ffd91fda7af157b4d15>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <9c9f068c46c64ffd91fda7af157b4d15>:0)
MetroCSharpVisualStudioSolutionCreator.WriteSolutionFile (System.String solutionFileName, UnityEditor.Scripting.ScriptCompilation.ScriptAssembly[] csharpAssemblies) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/MetroCSharpVisualStudioSolutionCreator.cs:166)
MetroCSharpVisualStudioSolutionCreator.CreateSolutionFileFrom () (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/MetroCSharpVisualStudioSolutionCreator.cs:722)
PostProcessWSA.CreateVisualStudioSolution () (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessWSA.cs:320)
PostProcessWinRT.Process () (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:237)
UnityEditor.WSA.BuildPostprocessor.DoPostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/ExtensionModule.cs:142)
UnityEditor.WSA.BuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/ExtensionModule.cs:149)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Note that I have “Unity C# Projects” and “Development Build” both active.
It seems to be the “Unity C# Projects” that triggers it.

My project.lock.json only ever had UAP,Version=v10.0 - nothing of the likes of a specific version (even though I build for version 14393) - still it does not work. So I am not sure that this fix does anything really. Maybe only in a specific type of configuration?

I’m seeing the same as DaTruAndi. Version 10.0 in the project.lock.json. VS version 15.2

@DaTruAndi @AccentDave_1 That issue is unrelated to the OP’s problem. What you’re experiencing is a known issue since B4 and it’s still present in B8. Hopefully, they’ll fix it soon, but it’s not a show stopper. You can still build, but you won’t be able to debug the scripts at runtime in VS.

I cannot build. I get a ton of errors, this one must be telling:?
error CS0518: Predefined type ‘System.Object’ is not defined or imported

@Handosa That worked perfectly! Thank you for saving me from having to downgrade Visual Studio.

This isn’t related. I believe you’re hitting a known issue in “Unity C# Projects” checkbox in 2017.2 beta. It is fixed in a future beta.

Hi,

are there any command line parameters I could you while installing VS2017 that would install an older version? I have a vs_enterprise.exe installer, which installs the latest version. Through the links provided above, I can download only a trial version of the VS2017 enterprise, which would solve the problem only temporarily.

Thanks.

I have a completely different behavior. Using Unity 2017.2.0b8, and Visual Studio 2017.3.2

HoloLens/UWP project builds from Unity without errors. The Visual Studio project created from Unity also builds and deploys without errors. However, any of the scripts attached to GameObjects do not initialize/execute. The scripts do execute in the Editor.

Can you make a new thread for unrelated issues?

Just FYI. New thread: https://forum.unity3d.com/threads/scripts-not-executing-in-uwp.489830/