Can't find System.Windows.Media namespace?
Asked Answered
P

7

104

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?

Postoperative answered 30/6, 2010 at 23:37 Comment(1)
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.Costello
H
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

Hoopen answered 30/6, 2010 at 23:41 Comment(4)
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.Specialistic
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.Oedipus
@Specialistic Hello from 2023! You were right. Link died and the answer is useless :PSpectrum
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.Hoopen
T
105

You should add reference to PresentationCore.dll.

Taction answered 8/10, 2012 at 5:57 Comment(7)
How to remember the references or solve this kind of problem when there is no internet access?Thiele
I downvoted this answer, because for newbies (like me) I have no clue where that file would live.Juristic
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!Pontius
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)Psalmbook
Add reference to what place?Manlove
Upvoted because I already knew how to add in references. All answers are predicated upon some level of knowledge. Which answer is better is subjective: I wanted a direct answer on which library contained what I was looking for. For someone new to Visual Studio, a longer answer may be pertinent. Though the argument can be made that they actually have two questions. What to add, and how to add it.Eugenioeugenius
But how.......?Fibroblast
H
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

Hoopen answered 30/6, 2010 at 23:41 Comment(4)
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.Specialistic
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.Oedipus
@Specialistic Hello from 2023! You were right. Link died and the answer is useless :PSpectrum
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.Hoopen
C
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

Cavorilievo answered 18/6, 2013 at 9:30 Comment(0)
P
22

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.

Petersham answered 27/2, 2021 at 17:8 Comment(2)
This is a Good Solution . I am working with Asp.net Blazor and adding this to csproj file it works .Bertsche
This solution worked when I created a .NET 6 project in VSCode.Darb
G
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

Gerick answered 5/5, 2018 at 17:9 Comment(3)
Then I had to add WindowsBase.dll from the same directoryAdvent
Is there a nuget package for it?Hyperbole
It'll be under "Assemblies" btw.Trolley
H
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>
Harriot answered 12/7, 2022 at 12:41 Comment(1)
This is the way. Chances are you need WindowsBase.dll too and this will take care of that as well.Alderney
P
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.

Pulp answered 23/3, 2021 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.