Hello everyone,
I have a class that queries for data with direct SQL. I execute a query and do a while-loop on my resultset.
In the while-loop itself I fill a file which needs to be stored on a specific location.
I am working for a couple months in AX so I still need to learn many things.
I started with the following code:
...
FileIoPermission filepermission;
FileName tempGeneratedFile;
AsciiIo tempFile;
str output;
;
filepermission = new FileIoPermission(tempGeneratedFile, 'w');
filepermission.assert();
tempFile = new AsciiIo(tempGeneratedFile, 'w');
... some logic / sql statement ...
while(resultSet.next())
{
... some logic for the lines that will be written in the file ...
tempFile.write(output);
}
CodeAccessPermission::revertAssert();
...
Now when I compile this code above, i get the best practice: TwC: Assert usage of API AsciiIo.new because it is protected by Code Access Security.
I search on google for a solutions, but I can't make it disappear. I thought the CodeAccessPermission::revertAssert would do the thing, but it didn't.
I have 2 other classes that use similar coding and what I do extra there is set tempFile = null after the while-loop (I have read it somewhere) but that didn't help as well.
This best practice is not the worst thing to happen, but when I execute one of these classes in batch I get the following error (and batch status error) after full execution:
Request for the permission of type 'FileIoPermission' failed.
(S)\Classes\FileIoPermission\demand
(S)\Classes\WinAPIServer\getTempPath - line 13
...
So I search for this error, but I couldn't find a proper solution.
Does anyone has experienced this before and provide me a working solution ?
Thanks in advance,
Vincent