C# - I cannot reference HttpPostedFileBase
Asked Answered
X

2

14

I am using MVC .NET in a distributed environment with CSLA and I can reference HttpPostedFileBase from one of my web layers (eg Website.MVC), but I cannot reference HttpPostedFileBase from a separate layer (lets call it OtherLayer.Web).

Any idea on what I need to do to be able to call HttpPostedFileBase ? I am able to use HttpPostedFile in both layers - should I just use this instead?

The assembly references are basically the same - in Website.MVC I have:

namespace Website.Mvc.Controllers
{
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Web.Mvc;
  using System.Web;
  using System.IO;
  using PetOrganizer.Mvc.Helpers;
  using TrupanionPetInsurance.Web;

Whereas in my other layer i have:

namespace OtherLayer.Web
{
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Collections.Specialized;
  using System.Data;
  using System.Data.SqlClient;
  using System.IO;
  using System.Net.Mail;
  using System.Text;
  using System.Text.RegularExpressions; 
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Security;
  using System.Xml;
  using System.Xml.Serialization;
  using Csla;
  using iTextSharp.text;
  using iTextSharp.text.pdf;
  using TruDat.BusinessLayer;
  using TruDat.BusinessLayer.Billing;
  using TruDat.BusinessLayer.Data;
  using TruDat.BusinessLayer.Utility;
  using TrupanionPetInsurance.Web.EmailTemplateParser;
  using TruDat.BusinessLayer.DataServices;
Xenocryst answered 15/12, 2009 at 23:15 Comment(0)
H
34

Make sure your project references the System.Web.Abstractions assembly which contains the HttpPostedFileBase type.

As confusing as it may seem, the HttpPostedFile type lives in a separate assembly (System.Web) but the same exact namespace.

It is important to remember that the namespaces can span assemblies and the name of an assembly does not necessarily dictate the namespace of the types contained in it. There is no System.Web.Abstractions namespace simply two assemblies that contain types in the System.Web namespace.

Once you have referenced both assemblies you can reference both types by their unqualified names with this single using statement:

using System.Web;
Highup answered 15/12, 2009 at 23:16 Comment(5)
For some reason I cannot reference System.Web.Abstractions - I get the error: Error 1 The type or namespace name 'Abstractions' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)Xenocryst
Hi Teddy, my answer to your comment was too long so I updated my post above instead :)Highup
Ok, co worker of mine figured this one out - I just had to add the reference to System.Web.Abstractions in OtherLayer.Web. I can reference HttpPostedFileBase now. Thanks for the help!Xenocryst
Thanks! I knew that namespaces could span assemblies, but that is an easy lesson to forget. Definitely appreciate the insight!Lyns
As @Alundrathedreamwalker wrote but more updated- almost 7 years later and still a good answer!Gladsome
M
0

Make sure your project references the System.Web.Abstractions assembly which contains the HttpPostedFileBase type.

Thanks, Andrew Hare, that did the trick, yet I believe that from .Net 4.0 and so on, System.Web.Abstractions is deprecated, and you should add reference to System.web instead.

In my case, that was the ultimate solution, after that

using System.Web;

worked, and therefore, HttpPostedFileBase was recognized.

Thanks.

Milfordmilhaud answered 27/3, 2016 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.