3

I am trying to use Petapoco's multi-poco query.

The code works fine on my local machine running .NET 4.6.1 but throws System.Security.VerificationException when deployed to the hosting I am using which is running .NET 4.5.

Snipppet from PetaPoco/Database.cs:2253

while (true)
{
    TRet poco;
    try
    {
        if (!r.Read())
            break;
        poco = factory(r, cb); // <-- The exception happens here
    }
    catch (Exception x)
    {
        if (OnException(x))
            throw;
        yield break;
    }

    if (poco != null)
        yield return poco;
    else
        bNeedTerminator = true;
}

"cb" is the callback to map the pocos, but for the sake of the argument I made it just return the object that came through:

public Person MapRow(Person person, Category category, Country country) {
    return person;
}

I am calling the method like this:

db.Query<Person>(
   new[] { typeof(Person), typeof(Category), typeof(Country) },
   new PersonRelator().MapRow,
   sql
);

Any clues why this exception is being thrown?

AndreFeijo
  • 10,044
  • 7
  • 34
  • 64
  • I'm guessing "Operation could destabilize the runtime" indicates some kind of bug in the .NET Framework and/or JIT compiler -- you wouldn't get that error just from trying to run untrusted code. You could browse the related questions in the "Related" sidebar to the right, but I'm guessing your best bet might be to try to get your web host to upgrade you to a 64-bit OS (if it's not already) and to .NET 4.6.1, and see if that fixes the problem. – Joe White Feb 06 '17 at 00:29

1 Answers1

2

I think this is because the hosting environment is set to medium trust. Because PetaPoco generates IL code during normal operations, medium trust hosting environment will not allow it and will throw an exception.

Plebsori
  • 1,075
  • 9
  • 23
  • I doubt that would cause an "Operation could destabilize the runtime" error message. That error means something went *really* wrong. – Joe White Feb 06 '17 at 00:23
  • 1
    Changing it from 'medium' trust to 'full' trust made it work like a charm! (setting it to high might be enough though). – AndreFeijo Feb 08 '17 at 06:49