102

I'm using an object from a 3rd party API that has a property of type System.Windows.Media.ImageSource, yet I can't seem to find the System.Windows.Media namespace anywhere. If I try to add a reference to my project I don't see System.Windows.Media in the list of options. My project is also targeting .Net 3.5.

Is there something else I need to do to be able to access this namespace?

1
  • 3
    Just a small hint for anyone Googling this like I did some days ago: Your projects in your solution might have different framework targets, therefore if you don't find a reference always double check in which project the file you're looking at actually sits and if that project still targets some old .NET version.
    – Akku
    May 14, 2013 at 8:55

7 Answers 7

104

You should add reference to PresentationCore.dll.

7
  • 6
    How to remember the references or solve this kind of problem when there is no internet access? Jun 24, 2014 at 20:15
  • 20
    I downvoted this answer, because for newbies (like me) I have no clue where that file would live.
    – John
    Jul 30, 2014 at 20:43
  • 3
    Best answer so far. Also, I didn't know there was a search bar at the top of the reffernces window, here I am scrolling through trying to find things to add in references. Thanks for pointing that out!
    – allegory
    Aug 25, 2016 at 22:43
  • Yes, this is what needs to be done but answer by Mehmedov got my vote since he told me where it was. Not obvious by any means. Also there is a PresentationCore.dll in every version folder of .NET framework. Look in your project first to see which framework you are using (4.5, 4.6. 4.61, etc)
    – JustJohn
    Mar 27, 2017 at 13:39
  • Add reference to what place? Apr 23, 2019 at 13:32
68

The System.Windows.Media.Imaging namespace is part of PresentationCore.dll (if you are using Visual Studio 2008 then the WPF application template will automatically add this reference). Note that this namespace is not a direct wrapping of the WIC library, although a large proportion of the more common uses are still available and it is relatively obvious how these map to the WIC versions. For more information on the classes in this namespace check out

http://msdn2.microsoft.com/en-us/library/system.windows.media.imaging.aspx

4
  • 7
    If that link ever dies or if the page is redirected, this answer will be useless. Next time please have a real answer in your answer, like @MegaMilivoje's. Aug 9, 2013 at 14:57
  • 7
    How does one find out what DLL we need in these cases? The link has no mention of a DLL or even the word "presentation". Your answer works, but it's not clear how we'd ever solve this without asking for help.
    – Kat
    May 13, 2015 at 15:15
  • 2
    @leetNightshade Hello from 2023! You were right. Link died and the answer is useless :P Jan 4 at 16:21
  • The answer was "to add PresentationCore.dll to the references" guys. Link was just for more information. You can surely google "System.Windows.Media" if you want more information.
    – VOX
    Jan 10 at 6:49
41

Add PresentationCore.dll to your references. This dll url in my pc - C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll

19

For Visual Studio 2017

Find "References" in Solution explorer

Right click "References"

Choose "Add Reference..."

Find "Presentation.Core" list and check checkbox

Click OK

3
  • 1
    Then I had to add WindowsBase.dll from the same directory Dec 27, 2018 at 19:13
  • Is there a nuget package for it?
    – Demodave
    Apr 2, 2019 at 17:45
  • It'll be under "Assemblies" btw. Jul 16, 2020 at 4:20
19

You can add PresentationCore.dll more conveniently by editing the project file. Add the following code into your csproj file:

<ItemGroup>
   <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

In your solution explorer, you now should see this framework listed, now. With that, you then can also refer to the classes provided by PresentationCore.dll.

2
  • This is a Good Solution . I am working with Asp.net Blazor and adding this to csproj file it works . Jan 12, 2022 at 1:29
  • This solution worked when I created a .NET 6 project in VSCode.
    – Onosa
    May 10, 2022 at 0:38
2

I found an answer on CodeProject which worked for me.

Open your project file, the *.csproj file so you can edit it as a text file. If like me you were targeting net6.0 you'll see something like this:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <OutputType>WinExe</OutputType>
    </PropertyGroup>

</Project>

Now, instead of net6.0 you need to target net6.0-windows and you also have to set the UseWpf-flag. Then your *.csproj file should like something like this:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0-windows</TargetFramework>
        <UseWpf>true</UseWpf>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <OutputType>WinExe</OutputType>
     </PropertyGroup>

</Project>
1
  • This is the way. Chances are you need WindowsBase.dll too and this will take care of that as well.
    – gghuffer
    Jan 30 at 19:53
0

I my case I needed to specify Platforms tag - for some reason it did not work otherwise.

  <PropertyGroup>
    <!-- Must be here for this example, otherwise 'using System.Windows.Media.Media3D' does not work for intellisense -->
    <Platforms>x64</Platforms>
  </PropertyGroup>

Visual studio 2019 v16.9.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.