After upgrading from building our product in Visual Studio 2010 and .NET 4.0 to Visual Studio 2015 and .NET 4.5.2 we have seen issues running the product on a customers machine.
The error we see is a System.MissingMethodException
being thrown when starting the application, which from looking at posts on here point to an incorrect version of .NET being installed on the machine. Now the customers machine does have .NET 4.5.2 installed as this is installed during the installation of our product.
The way we have currently fixed the issue is to install .NET 4.6 on the customers machine.
I have a theory that I ideally want to confirm (well preferably rubbish and replace with something more viable):
- All of our projects are set to compile against .NET 4.5.2
- The build agent that compiles the code and generates the installer has Visual Studio 2015 and with it .NET 4.6 but it does have the necessary .NET 4.5.2 framework installed
I believe that because .NET 4.6 is installed the machine it is overriding the .NET 4.5.2. I don't know why this would be happening but I have seen something vaguely similar where a .NET 4.0 application running on a machine with .NET 4.5 installed behaves how a .NET 4.5 application would here (if it is I am pretty sure it shouldn't be). I was hoping someone might be able to point out something that I am missing.
I do hope that my theory is wrong.
Additional Information
I have managed to attach a debugger when the application crashes and the error is:
Method not found: '!!0[] System.Array.Empty()'.
There is nothing in my code that uses Array.Empty().
StackTrace:
at MyApp.DisplayExceptionInfo(Exception ex)
at MyApp.Main(String[] args) in E:\Build\MyApp\App.xaml.cs:line 82
DisplayExceptionInfo
simply tries to display an Exception which makes me believe that an Exception is being thrown earlier.
Main
checks to see if there is another instance running through some Interop (which I also tried removing but it did not resolve the crash) and then creates my App class and runs it.
Update
Sorry I don't believe I gave enough details in my question to help get to the bottom of the issue. It turns out that TeamCity uses MSBuild to build Visual Studio solutions and during the build there is the following warning (annoyingly rather well buried in the log):
[GetReferenceAssemblyPaths] C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1097, 5): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
I can confirm that I do have the .NET 4.5.2 Multi-Targeting Pack installed but I will continue to investigate