Yasen Raykov
Yasen Raykov

Reputation: 227

Add references to PresentationCore.dll and PresentationFramework.dll in .NET API

I'm trying to reference PresentationCore.dll and PresentationFramework.dll in .NET 5 API but apparently it requires also WindowsBase, this is the error I get:

"System.TypeLoadException: Could not load type 'System.Windows.DependencyObject' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."

If I try to add reference to Windows.Base, it shows error in Visual Studio:

e

Upvotes: 10

Views: 18364

Answers (1)

magicandre1981
magicandre1981

Reputation: 28766

What you want to do is to add a WPF reference. This is not required if your csproj includes the net5.0-windows entry for TargetFramework and <UseWPF>true</UseWPF>

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>

This UseWPF entry automatically adds all WPF references and you can use WPF calls.

Upvotes: 29

Related Questions