Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:43:27+00:00 2026-06-11T17:43:27+00:00

As a preface, I’ve looked at every StackOverflow question matched by searching for this

  • 0

As a preface, I’ve looked at every StackOverflow question matched by searching for this error (25 of them or so), and none of them seemed to address the problem I’m having.

I’m building up a PermissionsDialog that inherits from System.Windows.Form. Within the method that calls dialogPermissions.ShowDialog() I am retrieving some Role objects from the database and loading them into a couple of ListBoxes. That was working just fine, but now I need to override one of the properties of the Role objects I’m adding to the listboxes using this pseudocode process:

  • iterate over the List of Roles
  • look up a matching item out of a List of Profiles using List<T>.Find()
  • look up a property on the Profile
  • build up a new Role and set the Name property as needed
  • add the Role to a list of Roles for the PermissionsDialog

All of that goes smoothly, but when I call dialogPermissions.ShowDialog() the underlying framework code throws an AccessViolationException.

Here is what I believe to be the relevant code:

List<UserProfile> userProfiles = new List<UserProfile>();
List<Role> allRoles = new List<Role>();
dialogData.AllRoles = new List<Role>();

using (var objectContext = this.SiteContext.CreateObjectContext())
{
    userProfiles = rs.UserProfiles.FindAll().ToList();
    allRoles = rs.Roles.FindAll();
}

foreach (Role role in allRoles.Where(role => role.BuiltInId == (int)BuiltInRoleId.UserProfileRole)) {
    var userProfile = userProfiles.Find(up => role.Id == up.Id);

    var roleToAdd = new Role {
        BuiltInId = role.BuiltInId,
        Description = role.Description,
        DirectoryEntry = role.DirectoryEntry,
        Id = role.Id,
        IsBuiltInRole = role.IsBuiltInRole,
        Name = null != profile ? profile.DisplayName:role.Name
    };
    dialogData.AllRoles.Add(roleToAdd);
}

My suspicion is that this is somehow a deferred execution issue, but triggering execution by calling ToList() on dialogData.AllRoles before calling ShowDialog() doesn’t resolve the issue. When I replace profile.DisplayName with a constant string I do not get the error.

Any clues what’s going on under the covers here, or how to find out what’s going on, or how to approach the problem differently so I can avoid it? All suggestions welcome 😉

CONCLUSION

So here’s the actual issue, I think:

Setting the Name property of the Role to null is just fine, but when the dialog tries to create a ListBoxItem out of the Role and uses the Role.Name property for the ListBoxItem’s Content property (which is an Object), that can’t be set as null and throws down in the framework code that’s building up the dialog. Checking to make sure I had a value in there fixes the issue.

Seems like s strange exception to throw, but there you have it….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:43:29+00:00Added an answer on June 11, 2026 at 5:43 pm

    You test for profile != null, but don’t test for profile.DisplayName != null so that’s the first thing that comes to mind from just looking at your sample.

    Standard exception finder is to go to Debug\Exceptions and check the box for break on thrown so you can see all the state when the exception is thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface: I have looked all over stackoverflow.com and google for this. I have found
Preface : I'm honestly not sure if this should be on StackOverflow, SuperUser or
Preface: This is not a homework question. I'm going through an algos book in
Preface: This question is about a project I am working on with a professor
Please let me preface this question with an apology. I am very new to
First let me preface this question by saying that I'm fairly new to Javascript.
To preface this question, I have a competent understanding of OpenGL and the maths
To preface, I've seen the command to answer this question before, but now I
To preface this question, this is my first app and I have a very
(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011 ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.