xdhmoore
xdhmoore

Reputation: 9876

Visual Studio 2019 - Could not locate the assembly "Windows"

I'm trying to use this PoshWinRT .NET/Powershell library, as described in this blog post, and this SO question. This worked for me before on Windows 7, but now I am on Windows 10 and since I've moved to a new computer I've cleared the assemblies cached during the build.

The code uses several classes such as Windows.Foundation.IAsyncAction, which are failing because of a missing "Windows" assembly:

CS0012 The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. PoshWinRT D:\projects\PoshWinRT\PoshWinRT\AsyncActionWrapper.cs 21

As well as an error about that assembly:

Could not resolve this reference. Could not locate the assembly "Windows". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

In the right-hand Solution Explorer, the following properties are shown for the "Windows" dependency in my References list:

enter image description here

The above .winmd has been deleted, but now I'm not sure how to re-add it. I've tried adding things like:

System.Windows
Windows.Foundation
Windows.Storage
Windows.System

But without any luck. How do I re-add the "Windows" assembly? I am guessing that either classes have moved around since I last used this code or maybe this is a wrapper for native code that needs to be included in some special way. Or maybe I don't have the right library installed. I've installed the VS WinRT extension, but that didn't help.

I should say that I'm hoping to import this in pwsh (core), where before it was running in pre-core powershell.

Upvotes: 3

Views: 2786

Answers (2)

somethingRandom
somethingRandom

Reputation: 1157

For anyone that's encountering the followings errors:

The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

and is using reactive extensions package, the errors might be due to a conflict with the package System.Runtime.WindowsRuntime.

Just remove that package and the errors will disappear.

More info here.

Upvotes: 2

magicandre1981
magicandre1981

Reputation: 28766

The windows.winmd is part of the Windows 10 SDK.

enter image description here

You can find the file for the Buildnumber of your installed SDK under C:\Program Files (x86)\Windows Kits\10\

Upvotes: 4

Related Questions