Thursday, September 10, 2009

Error: "Request for the permission of type 'InteropPermission' failed."

Hi there,

Here's another error message you may come across in Dynamics Ax:

Error: "Request for the permission of type 'InteropPermission' failed."

You have written some code, tested it and everything went fine. Now the project has gone live, and all of a sudden, the code fails with the error message from above.
The code is probably executed in another context as when you tested it. For example by another user, or in batch.
The reason for the failure is the security measures that were implemented in Ax 4.0 and up.
What do you need to do? Assign permissions to execute the code (CLR Interop). Like this:

InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
;
permission.assert();


If your error message is regarding a COM object that you are referencing, you can use this alternative:

InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
;
permission.assert();

You can read more about CAS or Code Access Security over at MSDN.

2 comments:

  1. When i run the batch its show some errors:
    Request for the permission of type 'InteropPermission' failed.
    (s)classes\Interpermission\demand
    (s)classes\CLRObject\new
    (s)classes\oocbankrecomovefiles\removezerochar - line 3
    (s)classes\oocbankrecomovefiles\fetchfiles - lines 22

    please help me..

    thanks

    ReplyDelete