Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roles.GetRolesForUser throws exception Object reference not set to an instance of an object

I have an ASP.NET application that uses the Roles.GetRolesForUser method. The call work fines within the application, but when i use the same call in a referenced library, it throws an exception. The exception message is:

Object reference not set to an instance of an object

The strange things is that when i check Roles, it is instantiated.

My code looks like this:

var roles = Roles.GetRolesForUser(userName);

Any suggestions?

like image 887
jason Avatar asked Nov 06 '13 08:11

jason


1 Answers

NOTE: according to the OP's comment himself, this answer solved his problem.

This is a .NET Framework bug.
To solve this issue call:

string[] roles = Roles.Provider.GetRolesForUser(userName);

here is a very similar question.

like image 64
Hakan Fıstık Avatar answered Oct 25 '22 03:10

Hakan Fıstık