8 Replies Latest reply on Aug 4, 2017 4:27 PM by natdavidson

    Installing AFSDK Code as a service

    natdavidson

      I have a some AFSDK code that is looking at a folder location in a timed cycle, when it finds a file, it parses it and updates AF attributes for multiple different elements, and this I want to run as a service. I've created windows services in the past, i'm no expert though. With the bit of code i have now, I go through the normal process of making an installer for the service code, go to run the resulting installer and get this error:

       

      "Error 1001. Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\[company]\[projectName]\[projectName].exe' or one of its dependencies. An attempt was made to load a program with an incorrect format."

       

      I've set the setup project to prefer x64 bitness, and also anywhere else i've set it to compile for x64. Could the reason i'm getting this error be that the AFSDK is only for 32-bit? I get an error about not being able to use 32-bit when my project was set for 32 bit (the default).

       

      I can provide sanitized code if needed, just wondering if i'm doing something wrong with 64 bit vs. 32 bit.

        • Re: Installing AFSDK Code as a service
          John Messinger

          Hi Nate,

           

          This does sound like a bitness related issue, and raises a couple of additional questions for you. How are you installing your service - are you using installutil? This error can occur when using the wrong version of installutil - either incorrect framework version, or incorrect bitness. Examples would be you are using installutil.exe for .NET 2.0 but your target executable is built with 4.x, or you are using a 32-bit version of installutil on a 64-bit dll/exe. It would also be worth checking the installed AF SDK on the target system - are you calling the same .NET Framework version of the AF SDK (compiled against 4.0 version AF SDK, but only 2.0 version is installed on target machine).

           

          MSDN doc discusses this in a bit more detail.

          3 of 3 people found this helpful
          • Re: Installing AFSDK Code as a service
            GreenTech

            Hi Nate,

            Definitely should be doing a 32 bit build if you are accessing 32 bit libraries: what's the error that you get with 32 bit? Are you loading any other assemblies (possibly 64 bit versions?). All of our self-installers inherently build with the main project so they are inherently the same bitness and .net framework-ness. Are you installing on the development machine? There are a few tricks with services to allow them to run directly from the IDE (or a command line) that can be a real time saver for debugging.

            Cheers,
            Rob

            2 of 2 people found this helpful
            • Re: Installing AFSDK Code as a service
              Rick Davin

              Hi Nate,

               

              AF SDK is compatible with both 32 and 64 bit applications.  I personally prefer to use 64 bit whenever I can.  While AF SDK is happy with my preference, there may be other libraries that you are referencing that demand 32 instead of 64, or vice versa.

               

              If you have a 64 bit OS, you will find the AF SDK in the typical 32 bit folders: C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0

               

              Don't be fooled into thinking this location means the AF SDK is 32 bit.  The dll's there are for Any CPU.

              3 of 3 people found this helpful
              • Re: Installing AFSDK Code as a service
                natdavidson

                Thanks everyone for you helpful responses. I was able to get the service to build and install. It seemed my original problem was building the application using "any CPU", 64-bit and 32-bit verisions all as options under the build menu. My solution was to stick with 32-bit and delete the other possible builds under the build menu, thought that was odd though. So my next question is, but Rick Davin has already hinted at this, is the AFSDK targeted only for 32-bit? I thought it would be able to be built using either. AFSDK was the only 3rd parth SDK i was using, everything else was from microsoft.

                  • Re: Installing AFSDK Code as a service
                    jnoss

                    The AFSDK is built AnyCPU as Rick mentioned. It will load fine in both 32 bit and 64 bit processes, and we test the same code in both environments. What version of AF, .NET, and Visual Studio are you using for development? If you are using .NET 3.5 or a version of AF prior to 2.5 there are dependencies in the AFSDK that reference non-.NET components where bitness matters. Also older versions of Visual Studio will default to setting exe projects to 32 bit, and it can be tricky to turn off.

                    4 of 4 people found this helpful