问题
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