I'm trying to use System.Windows.Media.ImageSource inside of a console application that targets netcoreapp3.1. Looking at the documentation from Microsoft here it looks like it's available for .NET Core 3.0 and 3.1
Applies to NET Core 3.1 3.0
My sample code will run just fine when it's a net472 but as soon as I change back to netcoreapp3.1 it will fail to build.
Demo App
using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ImageSourceTesting
{
internal static class Program
{
private static void Main()
{
ImageSource myImage = new BitmapImage();
Console.Write(myImage);
}
}
}
When attempting to build I see the following:
[CS0234] The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
System.Windows.Media.ImageSource is a part of WPF, so if you created console application, then you have to add WPF support in project using UseWPF tag like in example:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With