0

.NET 5.0 I'm getting an error trying to use HttpPostedFileBase:

The type or namespace name 'HttpPostedFileBase'could not be found(are you missing a using directive or an assembly reference?)

I have included using System.web but it isn't doing anything at all.

[NotMapped]
[RegularExpression(@"([a-zA-Z0-9\s_\\.\-:])+(.png|.jpg|.pdf|.doc)$", ErrorMessage = "File type not allowed. File must be .png, .jpg, .pdf, or .doc.")]
public HttpPostedFileBase PostedFile { get; set; }

I have a different project that is very very similar and this works just fine in that project. Both are ASP.NET Core Web App using Entity Framework.

So what is the problem? Why would this work fine in 1 project but not another?

Cole Perry
  • 333
  • 1
  • 5
  • 27
  • Nope. Don't want to use IFormFile. I want to use HttpPostedFileBase and I know that it is available because again, the project that I used as a template for the one I'm currently working on does include HttpPostedFileBase. I appreciate the quick response though! – Cole Perry Jan 21 '21 at 15:59
  • @ColePerry "I have a different project that is very very similar and this works just fine in that project. Both are ASP.NET Core Web App using Entity Framework." Similar != same. What version of ASP.NET Core is the failing application targeting as apposed to the one in which it works? – Ryan Wilson Jan 21 '21 at 16:01
  • What .Net version was the program you are referencing? From what I can find, that class doesn't exist in any version of .Net Core or .Net 5. – gunr2171 Jan 21 '21 at 16:01
  • How do I find out what version each is using? – Cole Perry Jan 21 '21 at 16:05
  • Look at the csproj file. It should say the target framework version. – gunr2171 Jan 21 '21 at 16:10
  • No csproj file. – Cole Perry Jan 21 '21 at 16:11
  • @gunr2171 .NET 5.0 – Cole Perry Jan 21 '21 at 16:13
  • 1
    [The requested page (the HttpPostedFileBase Class) is not available for .NET 5.0.](https://learn.microsoft.com/en-us/dotnet/api/system.web.httppostedfilebase?view=netframework-4.8&viewFallbackFrom=net-5.0), it only exists in .Net 4.8 or lower. – gunr2171 Jan 21 '21 at 16:15
  • @gunr2171 Ok after doing a lot of digging around I think I finally understand what I've done wrong. Thank you very much! – Cole Perry Jan 21 '21 at 16:25

0 Answers0