Bojensen Blogs

Stack trace: Invalid attempt to call WinAPI::findFirstFile running in CIL on the client.

This error you will normally encounter when running a batch job. The issue is that batch processing doesn’t suppport WINAPI::findFirstFile method. Actually I was trying to find a file in the folder and moving to some other folder, you can use this alternative:

public void run()
    System.IO.DirectoryInfo di;
    System.Type arrayType;
    System.Array array;
    System.IO.FileInfo fi;
    FilePath filePath, moveFilePath, shortFile;
    int i;
    int l;
    baseFolder = tEC_InterfaceSetup.TEC_DefaultFolder +””;
    di = new System.IO.DirectoryInfo(baseFolder);
    arrayType = System.Type::GetType(“System.IO.FileInfo”);
    array = System.Array::CreateInstance(arrayType, 1);
    array = di.GetFiles(“*” + #txt);
    l = array.get_Length();
    if (l > 0)
        //Find the files in the base folder and iterate.
        for (i = 0; i < l; i++)
            fi = array.GetValue(i);
            mainFolder = fi.get_FullName();
            foundBaseFileName = fi.get_Name(); 
         //**********Your logic************
        InterfaceTransfer::moveFile(foundBaseFileName , moveFilePath);

server static void moveFile(str fileName, str newFileName)
    Set                 permissionSet;
    permissionSet =  new Set(Types::Class);
    permissionSet.add(new FileIOPermission(fileName,#io_write));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    System.IO.File::Move(fileName, newFileName);

Hope this helps.

Comments are closed.