0
votes

I currently have a controller in my WebAPI that is returning a list of some items in my database:

As below:

public ICollection<TherapyGroup> OffUnit()
{                
      return _context.TherapyGroups.OrderBy(g => g.Name)
                     .Where(x => x.GroupTypeOffUnitOnUnit == TherapyGroup.OffUnit)
                     .ToList();               
}

Everything works fine when I am testing against my local database; however, when I switch out the database string for a remote database it throws a System.AccessViolationException. Based upon breakpoints, the data is being returned from the database fine, and it seems the problem is happening when the method returns to the WebApi in MVC. This has become a very frustrating issue, and I would love any help to navigate it.

The error window that is popping up: enter image description here

1
Can you please provide the stack trace from the exception you're seeing? - Eduard Malakhov
I don't see a stack trace... Note that the violation is happening in an unknown module. - Cody Short
Please add try catch block in your code. Then put more details. - Bigeyes
In .net whenever you get an exception, you have the stack trace. It is very unlikely that in your case it is much different. - Eduard Malakhov
Here may be providing some help. - Bigeyes

1 Answers

0
votes

Decorate the methods you want to catch these exceptions in with the HandleProcessCorruptedStateExceptions attribute. See https://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035 for details.

[HandleProcessCorruptedStateExceptions] 
[SecurityCritical]
public ICollection<TherapyGroup> OffUnit()
{
      try
      {
          return _context.TherapyGroups.OrderBy(g => g.Name).Where(x => x.GroupTypeOffUnitOnUnit == TherapyGroup.OffUnit).ToList();
      }
      catch (Exception e)
      {
          // set break point to see the stack trace.
          Debug.WriteLine(e.InnnerException);
          return null;
      }
}