Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

razor

I'm following the tutorial on Hangfire.io: http://docs.hangfire.io/en/latest/tutorials/send-email.html

However when I copy and pasted the provided ~/Views/Emails/NewComment.cshtml code:

@model Hangfire.Mailer.Models.NewCommentEmail

To: @Model.To
From: [email protected]
Subject: New comment posted

Hello,
There is a new comment from @Model.UserName:

@Model.Comment

<3

I ran into the following error:

Error   2   The type or namespace name 'Hangfire' could not be found (are you missing a using directive or an assembly reference?)
Error   3   The name 'Model' does not exist in the current context  

Models/NewCommentEmail.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Postal;

namespace HangFire.Mailer.Models
{
    public class NewCommentEmail : Email
    {

        public string To { get; set; }
        public string UserName { get; set; }
        public string Comment { get; set; }
    }
}

It seems when I create almost any other type of Views: in Views/Email: "MVC 5 View Page (Razor), MVC 5 View Page Layout (Razor)...", the page shows all elements preceded with "@" as can't find in current context. The Project Soln name is "Hangfire.Mailer".

like image 580
jerryh91 Avatar asked Jan 15 '15 16:01

jerryh91


2 Answers

C# is case sensitive so you should use Hangfire or HangFire.

Now you are using uppercase in the definition:

namespace HangFire.Mailer.Models

But lowercase in the reference:

@model Hangfire.Mailer.Models.NewCommentEmail

The page you linked to uses lowercase in the namespace:

namespace Hangfire.Mailer.Models
like image 66
Ulf Kristiansen Avatar answered Sep 28 '22 07:09

Ulf Kristiansen


First, (of all, you need to) install the Postal NuGet package to be able to use this class.

source: http://docs.hangfire.io/en/latest/tutorials/send-email.html#installing-postal

Installation package: https://www.nuget.org/packages/Postal.Mvc5/

like image 29
Maciej Los Avatar answered Sep 28 '22 06:09

Maciej Los