System.IO.Packaging
Asked Answered
K

8

118

I have my project set to .NET Framework 4.0. When I add System.IO.Packaging, it says that it doesn't exist. It also doesn't show up when I try to add it as a reference to the project.

How can I add System.IO.Packaging to my C# project?

Kiernan answered 31/8, 2011 at 16:33 Comment(0)
G
174

According to a user comment on this MSDN page, you have to add a reference to the WindowsBase .Net library.

Galumph answered 31/8, 2011 at 16:37 Comment(3)
You don't even need a user comment. If you look at the docs for any of the actual methods/objects/etc. in the namespace, they all say "Assembly: WindowBase.dll"Fenella
When I went to the link in the answer, I didn't see how I would know to add the WindowsBase.Net library. I added it and I now have access to system.io.packaging. So thanks for that, but could you explain what I'm not seeing about knowing to access the system.io.packaging through the WindowsBase.Net library?Confiteor
The page used to have user comments which mentioned WindowsBase. It looks like Microsoft removed comments from their docs.Galumph
P
82

For a C# solution in Visual Studio 2010 with .NET 4.0:

  1. In your project's Solution Explorer, right-click on References and select Add References from the context menu.
  2. Select Assemblies in the left-hand pane, then click the Browse button next to the File name field near the botton of the pane.
  3. Browse to .NET 4.0 reference assemblies and select WindowsBase.dll. For example, on my machine (Windows 7, 64-bit) the complete path is:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll

Save the solution (especially if you're compiling from the command-line with MSBuild) and you should now be able to add the using System.IO.Packaging directive to the top of your .cs file without an error appearing.

Petigny answered 18/10, 2011 at 22:34 Comment(2)
No need to browse to dll, it's already available under Assemblies > Framework.Latia
@AltafPatel for me it didn't show up, I had to browse to it. Also make sure that your project is set to compile with the matching .NET version of the referenced file(in this case 4.0).Roche
S
5

System.IO.Packaging is a namespace, not a reference. Most (all?) of the classes within the namespace, such as ZipPackage, are deployed in WindowsBase.dll.

Make sure you have a reference to WindowsBase.dll - if you do, you can just add: using System.IO.Packaging; to your .cs files, and you'll be fine.

Note that you can see this in the documentation for any class on MSDN. For example, in ZipPackage, it lists:

Namespace:  System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)
Syndactyl answered 31/8, 2011 at 16:38 Comment(1)
+1 - I didn't notice that individual pages note the assembly to use. I would have expected it on the main namespace page, but since those don't always match up, it makes sense to look at the classes you might need.Galumph
N
5

We can add WindowsBase.dll in Dot Net framework 3.5 as well. I am using XP machine and Path for WindowsBase.dll is

C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client\WindowsBase.dll

Example for using System.IO.packaging is given here -

Using System.IO.Packaging to generate a ZIP file

Now answered 5/12, 2012 at 6:38 Comment(0)
R
3

The System.IO.Packaging namespace is provided by WindowsBase. When you add a reference, add WindowsBase as the reference instead of trying to find System.IO.Packaging.

Riane answered 31/8, 2011 at 16:39 Comment(0)
A
3

You need to add a reference to the WindowsBase.dll. System.IO.Packaging is located in there.

See this article for more details:

http://msdn.microsoft.com/en-us/library/system.io.packaging.package.aspx

Asir answered 31/8, 2011 at 16:39 Comment(0)
A
2

System.IO.Packaging v4.0.30319 is in WindowsBase.dll v4.0.30319

For windows 10 maybe you could found here

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\

Ashworth answered 29/9, 2017 at 9:34 Comment(0)
G
0

In my case I was using a ashx handler. For it to work you need to add the assembly to the project and the handler:

<%@ WebHandler Language="C#" Class="UploadExcelFile2" %>
<%@ Assembly Name="WindowsBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

This finally worked for me, tried multiple times to add WindowsBase as reference(restarted VS, restarted machine too) but still it was not working till I added this explicitly in my aspx page. I used: <%@ Assembly Name="WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> as the dll i had referenced was version 4.0.

Geehan answered 16/2, 2018 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.