Petapoco: Operation could destabilize the runtime

心不动则不痛 提交于 2019-12-10 20:15:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41735678/petapoco-operation-could-destabilize-the-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!