0

With p4api.net, I can not load p4bridge.dll.

I can't add it as a reference to the solution without getting the following error:

enter image description here

If I don't include it, I get the following runtime exception:

Test method CFTT.Business.Test.GeneralTests.ddddd threw exception: System.DllNotFoundException: Unable to load DLL 'p4bridge.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

If I manually copy the the dll to the build output directory without explicitly referencing it I also get get the above error, though I'm running this threw the unit test, so it may be a side path-ing issue.

The above is with the 32 bit, if I try to use the 64 bit (which I would rather), I also get the same error with the p4bridge.dll but at run time, I get:

Test method CFTT.Business.Test.GeneralTests.ddddd threw exception: System.BadImageFormatException: Could not load file or assembly 'p4api.net, Version=2013.2.66.1822, Culture=neutral, PublicKeyToken=f6b9b9d036c873e1' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Does anyone have any experience with these issues?

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
Matt
  • 25,943
  • 66
  • 198
  • 303
  • Did you build the p4api.net from source downloaded at the Perforce FTP? If not where did you get it? – EkoostikMartin Jul 08 '13 at 19:56
  • It seems that p4bridge.dll is a native library, so you can't add a direct reference to it from .net. You'll need to crate a PInvoke wrapper first. What are you trying to do? – Oscar Jul 08 '13 at 19:57
  • I just downloaded the libs from the site, not the FTP. I'll check that out. – Matt Jul 08 '13 at 20:02

2 Answers2

6

You need to add a reference to p4api.net.dll - this is the .Net assembly.

p4bridge.dll is a native COM enabled library, which I believe needs to be in the same directory but does not need to be referenced directly from your code.

EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62
  • 1
    Additionally you should ensure that your .NET program/library platform is set correctly based on the p4bridge.dll, rather than using the "Any CPU" target. For example, if your p4bridge.dll is 32-bit you'll have to set your target platform to x86, otherwise if you use "Any CPU", when you run your program on a 64-bit OS it will run as a 64-bit process and fail to load the 32-bit p4bridge.dll. – Sam Jul 23 '15 at 01:16
1

I've posted a solution for this issue that allows you to build p4api.net using the Any CPU target and have it automatically work on both x86 and x64 architectures: Building p4api.net.dll for 'Any CPU'

Hope this helps anyone who stumbles upon this question looking to solve this problem in the future!

Community
  • 1
  • 1
PfhorSlayer
  • 1,337
  • 9
  • 14