I have a WinForms application, using the PI AFSDK. I am connecting to the PI Server via this code:
var ServerList = PIServers.GetPIServers(); //Exception thrown here.
foreach(PIServer server in ServerList)
PIServer = PIServers.GetPIServers().DefaultPIServer;
if (!PIServer.ConnectionInfo.IsConnected) PIServer.Connect();
catch (Exception ex)
MessageBox.Show("Could not connect to PI Server. See error log for details. \n\n Some functionality will be unavailable.", "PI Connection Error.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
It used to work with no problem, but in the last couple of days, I have started getting exceptions; not all the time, just some of the time: I am connecting to our office domain via a VPN, but as I said, it has been working fine up until a few days ago, and still works around 30% of the time now.
The type initializer for '<Module>' threw an exception.
Unable to load DLL 'PIInterop': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
==== STACK TRACE ====
at OSIsoft.AF.PI.PIServersGlobal.Load(Boolean force)
at OSIsoft.AF.PI.PIServersGlobal..ctor(PISystemsGlobal systems)
at OSIsoft.AF.PI.PIServersGlobal.GetPIServers(PISystemsGlobal systems)
at OSIsoft.AF.PI.PIServers.GetPIServers(PISystem system)
Searching for this, I found this link:
But this is not my problem - I can load the AF Client without issue, (and can load PI ProcessBook and datalink as well and get PI data, for what it's worth).
Here is the assembly info from PI System Explorer:
And here is the reference in my project:
As far as I can tell, I'm using the same library in my app as the PI System Explorer is using. My project is 32-bit, but I have tried 64 bit as well, that doesn't make any difference.
Any other suggestions? Do the OsiSoft applications use a different method to connect to the server?