值不能为空,抛出期望c#

本文关键字:期望 不能 | 更新日期: 2023-09-27 18:12:35

我有一个web应用程序,我在VS 2015调整,但我收到一个错误…见下文

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

描述:当前web请求执行过程中出现未处理的异常。请查看堆栈跟踪以获得有关错误及其在代码中的起源的更多信息。

Exception Details: System。ArgumentNullException:值不能为空。参数名称: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

这是导致错误private

的行

-> 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();
}

}

值不能为空,抛出期望c#

我怀疑UserPermissions的构造函数内部有问题。

可能,您缺少您想要获得权限的帐户的用户名。