Update-Database fails in Package Manager Console on Windows 10 Insider Preview with ambiguous type error


This post is about providing a workaround for this problem until Microsoft provide us with a proper fix.

This problem has been reported here:

There seem to be two types that fail due to ambiguity:

  • Microsoft.VisualStudio.Shell.Package
  • NuGet.VisualStudio.IVsPackageInstallerServices

Yet if you have other failing types in your scenario, understand this post and apply the same logic to your specific case.

Microsoft.VisualStudio.Shell.Package

This workaround fixes the following error:

Type name 'Microsoft.VisualStudio.Shell.Package' is ambiguous, it could be 'Microsoft.VisualStudio.Shell.Package, Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or 'Microsoft.VisualStudio.Shell.Package, 
Microsoft.VisualStudio.Shell.10.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

To fix this, do the following:

  1. Open Windows PowerShell ISE in admin mode (right click and Run as Administrator)
  2. Open the following file:
    • C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\EXTENSIONS\ZPM4HZQB.YOS\Modules\NuGet\Profile.ps1
  3. Go to line number 126 (Ctrl+G and enter the number)
  4. Find this line:
    • $service = [Microsoft.VisualStudio.Shell.Package]::GetGlobalService($ServiceType)
  5. Replace it with these lines:
    • $accel = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")
       $accel::add(“specificShell”,”Microsoft.VisualStudio.Shell.Package, Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”)
       $service = [specificShell]::GetGlobalService($ServiceType)
  6. If your Visual Studio is open, you will need to close it and re-open it, as it caches a copy of this script.

NuGet.VisualStudio.IVsPackageInstallerServices

This is a similar fix to the above, but for this error:

Type name 'NuGet.VisualStudio.IVsPackageInstallerServices' is ambiguous, it could be 'NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325' or 
'NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.PsiFeatures.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325'.

To fix this, do the following:

  1. Open Windows PowerShell ISE in admin mode (right click and Run as Administrator)
  2. Open the following file (replace {NuGetPackagesFolder} with the location of your packages folder in your solution:
    • {NuGetPackagesFolder}\EntityFramework.6.1.3\tools\EntityFramework.psm1
  3. Go to line number 1004 (Ctrl+G and enter the number)
  4. Find this line:
    • $packageInstallerServices = $componentModel.GetService([NuGet.VisualStudio.IVsPackageInstallerServices])
  5. Replace it with these lines:
    • $accel = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")
       $accel::add(“NuGetInstallerServices”,”NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325”)
       $packageInstallerServices = $componentModel.GetService([NuGetInstallerServices])
  6. As above, if your Visual Studio is open, you will need to close it and re-open it, as it caches a copy of this script.

The Logic

All I am doing here is quite simple, I am creating a type alias that points to a specific assembly instance, and using that for reference, rather than the version that would resolve into multiple instances.

A Few Notes

The workaround above, particularly the second one, is temporary, and will fail again if you refresh your NuGet package cache before MS come up with a fix for this problem.

Also, since all machines have different configurations, your specific assemblies might be different.  So just replace them above accordingly… you are all devs after all ;)

Of course, to fix, simply re-apply the patch above.

This problem is still present as of Windows 10 Insider Preview Build 14257.rs1_release.160131-1800

Advertisements