值不能为null抛出预期c#

时间:2015-09-14 13:00:33

标签: c#

我有一个网络应用程序我在VS 2015中调整但我收到错误...见下文

值不能为空。参数名称:String

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中的起源位置的更多信息。

异常详细信息:System.ArgumentNullException:值不能为null。参数名称:String

来源错误:

public abstract class MasterPageBase : System.Web.UI.MasterPage 
{
        private UserPermissions userPermissions = new UserPermissions();
        public string SelItem { set; get; }
        public RadWindowManager.WindowManager_Notice
        ...
}

堆栈追踪:

Stack trace [ArgumentNullException: Value cannot be null.

Parameter name: String]

System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10169561

System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +207

TmsAdministration.SecurityBase..cctor() +43

[TypeInitializationException: The type initializer for 'TmsAdministration.SecurityBase' threw an exception.]

TmsAdministration.UserPermissions.GetUserPermissions(String _sAMAccountName) +339

MasterPageBase..ctor() in c:\inetpub\wwwroot\calrecallnew2\App_Code\MasterPageBase.cs:7

MasterPage..ctor() +41

ASP.masterpage_master..ctor() in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\calrecallnew2\993de1dc\c159201a\App_Web_qz6jw_eo.2.cs:0

__ASP.FastObjectFactory_app_web_qz6jw_eo.Create_ASP_masterpage_master() in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\calrecallnew2\993de1dc\c159201a\App_Web_qz6jw_eo.10.cs:0

System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +270

System.Web.UI.Page.get_Master() +69

System.Web.UI.Page.ApplyMasterPage() +18

System.Web.UI.Page.PerformPreInit() +58

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1256

这是导致错误私有的行

---> UserPermissions userPermissions = new UserPermissions();

我对c#很新,希望得到一些帮助。

UserPermissions代码:

public static List<EnumValue>     GetUserLocations(TmsAdministration.U    serPermissions userPermissions)

    {

        List<EnumValue> locations = new List<EnumValue>();



        foreach (EnumValue value in Values)

        {

            if (userPermissions.IsInRole(value.Label) == 2 && !locations.Exists(_r => _r.Label == value.Label))

            {

                locations.Add(value);

            }

        }



        if (locations.Exists(_r => _r.Id == Default.DirectoryId))

        {

              locations.Remove(locations.Find(_r => _r.Id == Default.DirectoryId));

            locations.Insert(0, new EnumValue(Default.DirectoryId, Default.DirectoryName));

        }



        return locations;

    }

}

命名空间:

namespace TmsAdministration

{

public class UserPermissions

{

    public string Email;

    public string FirstName;

    public bool IgnoreCache;

    public string LastName;

    public Dictionary<string, int> Roles;

    public string sAMAccountName;

    public bool UserIsInActiveDirectory;



    public UserPermissions();

    public UserPermissions(string sAMAccountName);

    public UserPermissions(string sAMAccountName, bool ignoreCache);



    public string FullName { get; }



    public int GetRoleId(string roleName);

    public string GetRoleName(int roleId);

    public ActiveDirectory.UserInformation GetUserManager();

    public List<string> GetUsersDirectReports();

    public int IsInRole(int roleId);

    public int IsInRole(string roleName);

    public virtual void RedirectIfNotInActiveDirectory(Page page, string redirectUrl);

    public virtual void RedirectIfNotInRole(Page page, string roleName, int requiredLevel, string redirectUrl);

    public virtual void RedirectIfNotInRoles(Page page, List<string> roleNames, List<int> requiredLevels, string redirectUrl);

    public void RefreshUser();

}

}

1 个答案:

答案 0 :(得分:0)

我怀疑UserPermissions构造函数内部的某些内容失败。

您可能缺少要获取其权限的帐户的用户名。