Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Petapoco: Operation could destabilize the runtime

Tags:

c#

.net

petapoco

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?

like image 301
AndreFeijo Avatar asked Nov 30 '25 07:11

AndreFeijo


1 Answers

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.

like image 109
Plebsori Avatar answered Dec 02 '25 20:12

Plebsori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!