Показать сообщение отдельно
Старый 09.02.2010, 00:08   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Error: Multiple calls to CodeAccessPermission.Assert
Источник: http://alexvoy.blogspot.com/2010/02/...-calls-to.html
==============

Multiple calls to CodeAccessPermission.Assert
(S)\Classes\SkipAOSValidationPermission\assert
(S)\Classes\BatchRun\runJob - line 166
(S)\Classes\BatchRun\do - line 54
(C)\Forms\BatchRun\Methods\doBatch - line 18

Sometimes I got this error while working with Change based alerts batch processing. After that the status of the related job in batch list changed to Executing, and the only way to get rid of it was deleting that job.


This issue arises in [Classes]BatchRun.runJob method because of absence of closing revertAssert() method in case of exceptions after calling runas() method.

So, my solution is to comment the existing call of revertAssert()...

X++:
if (batchClass.runsImpersonated())
        {
            // Ok to assert here because the user name comes from
            // the batch table
            runAsPermission = new RunAsPermission(batch.CreatedBy);
            runAsPermission.assert();
            // BP Deviation Documented
            runas(batch.CreatedBy,
                classnum(BatchRun),
                staticmethodstr(BatchRun, runJobStatic),
                [batchId]);

           // Alexey Voytsekhovskiy (SIS) (2010/02/08) (Demande #0074)
           // CodeAccessPermission::revertAssert();
        }
        else
        {
            BatchRun::runJobStatic([batchId]);
        }
and move it after catching all kind of exceptions:


X++:
catch (Exception::UpdateConflictNotRecovered)
    {
        isErrorCaught   = true;
        exception       = Exception::UpdateConflictNotRecovered;
    }

    // Alexey Voytsekhovskiy (SIS) (2010/02/08) (Demande #0074)
    // in case of exception Permssion should be revert anyway!!
    CodeAccessPermission::revertAssert();
It allows to avoid multiple calls to CodeAccessPermission.Assert (there is another call far in this method) and see the log of the job ended with an error.


By the way, here is a short and sweet trick with multiple calls if needed.


Источник: http://alexvoy.blogspot.com/2010/02/...-calls-to.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.