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

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

  1. Thanks!

    Hmm… The first part (for Microsoft.VisualStudio.Shell.Package) worked great once found the appropriate Extensions subdirectory withthe culpable Profile.ps1 on my box. (Folks will want to search for the most recent match target for the patch.) But the second part of the fix (for NuGet.VisualStudio.IVsPackageInstallerServices) isn;t working for me:

    “`
    Cannot convert argument “type”, with value: “NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0,
    Culture=neutral, PublicKeyToken=1010a0d8d6380325”, for “Add” to type “System.Type”: “Cannot convert the “NuGet.VisualStudio.IVsPackageInstallerServices,
    JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325” value of type “System.String” to type
    “System.Type”.”
    “`

    Ok, fine. Looks like the ::add is expecting System.Type and not a System.String. That’s odd since the same signature worked for the previous fix… But I played along and edited the offending line which originally read

    $accel::add(“NuGetInstallerServices”,”NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325”)

    to read instead

    $accel::add(“NuGetInstallerServices”,[psobject].Assembly.GetType(”NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325”))

    and that got me one line further and here’s the new error:

    Unable to find type [NuGetInstallerServices].
    At C:\Users\Zippy\documents\visual studio 2015\Projects\TestMigrationsFix\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:1009 char:60
    + … tallerServices = $componentModel.GetService([NuGetInstallerServices])

    Looks like it’s finally time to learn powershell for real. :( now, :) later Thanks for the motivation.

  2. VS2015 Community + Win10 build 14257. The fix for NuGet.VisualStudio.IVsPackageInstallerServices in the EF6 package is throwing on $accel::add because it is expecting a System.Type (not a System.String) for the second parm. Ideas?

  3. After Making the suggested changes I get
    Cannot convert argument “type”, with value: “NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325”, for
    “Add” to type “System.Type”: “Cannot convert the “NuGet.VisualStudio.IVsPackageInstallerServices, JetBrains.Platform.VisualStudio.SinceVs11, Version=104.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325”
    value of type “System.String” to type “System.Type”.”
    At C:\WIP\Scheduler\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:1005 char:5
    + $accel::add(“NuGetInstallerServices”,”NuGet.VisualStudio.IVsPacka …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

anything to say?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s