Fix RPC error 1702 when calling a WinAPI method from a batch job

Updated: 14.06.2016

You may get the error “RPC error: RPC exception 1702 occurred in session xxx” in the Windows Event Log when some batch job is running. The error details are "The binding handle is invalid".  You can find the list of RPC errors here. This error is thrown because methods those are supposed to be executed on client actually were called on server in the batch mode.

Here is an example:

{{ client static boolean folderExists(Filename _filename)
{
boolean ret;
ret = System.IO.Directory::Exists(_filename);
return ret;
} }}

To fix that error you have to skip “client” and modify your code so it can be executed on server.

{{
InteropPermission interopPerm;
boolean isFolderExist;
;
interopPerm = new InteropPermission(InteropKind::ClrInterop);
interopPerm.assert();
isFolderExist = System.IO.Directory::Exists(@"c:\temp\");

if(isFolderExist)

{ info("Folder exists"); } else { info("Folder does not exists"); } CodeAccessPermission::revertAssert();}

}

 

Other blog posts

24.05.2018
Disclaimer
08.05.2018
We apply OKR methodology in Neti since 2014. We started from a quarterly planning, but then understood that no ambitious goals can be achieved per quarter. So we switched to semi-annual intervals....
11.04.2018
As you know, Microsoft recently has launched Dynamics 365 Business Central. And we are proud to announce we have launched intracompany training for sales and development departments:Why do we need it...

Subscribe for blog updates

Get updated with our blog new articles via your email!


Subscribe now