# Context.CandidateState never switches to FailedState

**URL:** <https://discuss.hangfire.io/t/context-candidatestate-never-switches-to-failedstate/1048>\
**Category:** question\
**Created:** [June 9, 2015, 8:55pm UTC](https://discuss.hangfire.io/t/context-candidatestate-never-switches-to-failedstate/1048 "2015-06-09T20:55:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmehta](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@dmehta](https://discuss.hangfire.io/u/dmehta)\
**Post date:** [June 9, 2015, 8:55pm UTC](https://discuss.hangfire.io/t/context-candidatestate-never-switches-to-failedstate/1048/1 "2015-06-09T20:55:25Z")

</div>

I am using Hangfire using SQL Server and MSMQ.

I have created a custom attribute as follows

public class CustomJobFilterAttribute : JobFilterAttribute, IElectStateFilter

and within OnStateElection(ElectStateContext context) I have a variable

var failedState = context.CandidateState as FailedState;

My method that processes the job throws an exception. The exception is visible in the Hangfire Dashboard under Failed State, but failedState variable within the attribute always remain null.

On attaching a debugger, I see that context.CandidateState is set to ProcessingState right after the exception and never to FailedState.

What I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Harsh\_Soni](https://avatars.discourse-cdn.com/v4/letter/h/f4b2a3/32.png) [@Harsh\_Soni](https://discuss.hangfire.io/u/Harsh_Soni)\
**Post date:** [March 29, 2018, 9:40pm UTC](https://discuss.hangfire.io/t/context-candidatestate-never-switches-to-failedstate/1048/2 "2018-03-29T21:40:17Z")

</div>

I am facing the same issue. Can you please help me here if you found the solution or work around for this ?

Thanks In Advance
