locked
Web API with referenced to Managed Code 32bit RRS feed

  • Question

  • User-1458727574 posted

    The Web API I'm creating links to Sage 300. When you reference the 2 DLLs that you need to connect to Sage's API, they are 32bit DLLs. If I set the project properties to be x86, running it loads the browser and then immediately exists with:

    'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.0\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The program '[14832] dotnet.exe' has exited with code -532462766 (0xe0434352).

    If I set it to Any CPU I get:

    System.BadImageFormatException: 'Could not load file or assembly 'ACCPAC.Advantage, Version=6.5.0.10, Culture=neutral, PublicKeyToken=4d7048ecf2312a7c'. An attempt was made to load a program with an incorrect format.'

    Now I know this is because the Sage DLLs are 32bit. In Visual Studio 2017 there is this option:

     Tools
      -> Options
       -> Projects and Solutions
        -> Web Projects
         -> Uncheck "Use the 64 bit version of IIS Express for web sites and projects"`
    

    It is unchecked. I checked it to see if it made a difference. It didn't. Any thoughts?

    Thursday, June 14, 2018 3:56 PM

Answers

  • User475983607 posted

    Don't suppose you can think of a way around it? Could I maybe, keep the web service and then pass off the processing to another application?

    I have no idea.  The error is referencing Windows.Forms.  Simply, it is not possible to host Windows Forms.  Of course there are exceptions but basically Windows Forms are designed to run on a desktop not a hosted service.  I would say it is unlikely.

    IMHO, the first step is learning how this Sage thing works.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 15, 2018 1:27 PM

All replies

  • User753101303 posted

    Hi,

    It is expect that Any CPU won't work.You should debug what happens with x86. According to http://ig2600.blogspot.com/2011/01/why-do-i-keep-getting-exception-code.html this is just the error code for most exceptions. You don't have any exception detail somewhere ???

    Thursday, June 14, 2018 9:13 PM
  • User475983607 posted

    Contact Sage 300 support and make sure the DLLs are compatible with ASP Core 2.1.  There are .NET standards must be meet in order to used ASP Core 2.1.

    I did a quick Internet search and did not find anything either way.  Try building an ASP.NET Web API project and see if you get different results.

    Thursday, June 14, 2018 10:47 PM
  • User-1458727574 posted

    Hi,

    It is expect that Any CPU won't work.You should debug what happens with x86. According to http://ig2600.blogspot.com/2011/01/why-do-i-keep-getting-exception-code.html this is just the error code for most exceptions. You don't have any exception detail somewhere ???

    During build I get this warning:

    1>E:\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ACCPAC.Advantage", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

    If I set it to x86 I can build but when I run it exits once it has finished loading with this error:

    'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.0\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The program '[14524] dotnet.exe' has exited with code -532462766 (0xe0434352).

    If I set to Any CPU and choose Prefer 32bit it runs until I get to the point where it tries to connect to Sage. I use Postman to send the XML. Stepping through the code gives me this error at the point it tries to connect to Sage:

    Error 500 internal server error.

    System.BadImageFormatException
    HResult=0x8007000B
    Message=Could not load file or assembly 'ACCPAC.Advantage, Version=6.5.0.10, Culture=neutral, PublicKeyToken=4d7048ecf2312a7c'. An attempt was made to load a program with an incorrect format.
    Source=ACLWebApi
    StackTrace:
    at ACLWebApi.SageHelper.SageLogin() in E:\LSProjects\ACLWebApi\ACLWebApi\SageHelper.cs:line 52
    at ACLWebApi.SageHelper..ctor(customersT customers) in E:\LSProjects\ACLWebApi\ACLWebApi\SageHelper.cs:line 28
    at ACLWebApi.Controllers.CustomersController.Post(customersT customers) in E:\LSProjects\ACLWebApi\ACLWebApi\Controllers\CustomersController.cs:line 46
    at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
    at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()

    Friday, June 15, 2018 8:32 AM
  • User-1458727574 posted

    After a lot of wasted time and searching around, I found an obscure reference to the dotnet core platform bitness and recalled that when I installed 2.1 I had no choice but to download what MS decided I should have. This was the 64 bit variety. Installing the 32 bit variety now after a bit of hunting to find the installer. Will see if that fixes it. So much wasted time!

    Friday, June 15, 2018 9:40 AM
  • User-1458727574 posted

    Uninstalled 64bit dotnet core 2.1 and installed 32bit version. Recreated the application from scratch. Added references to my 32bit DLLs. Set the build to be x86 and to use IISExpress in 32 bit mode.

    It can load the DLLs now. I've added some exception handling and I return the string to the client and I get this error:

    Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

    Friday, June 15, 2018 11:01 AM
  • User475983607 posted

    The assemblies are for use in a Windows Forms application not a hosted Web Application.  Contact Sage support and ask for assistance.  Explain that you are building an ASP Core Web Application.  

    Friday, June 15, 2018 12:07 PM
  • User-1458727574 posted

    Thanks. I emailed them earlier with just that question.

    Friday, June 15, 2018 12:54 PM
  • User-1458727574 posted

    Don't suppose you can think of a way around it? Could I maybe, keep the web service and then pass off the processing to another application?

    Friday, June 15, 2018 1:03 PM
  • User475983607 posted

    Don't suppose you can think of a way around it? Could I maybe, keep the web service and then pass off the processing to another application?

    I have no idea.  The error is referencing Windows.Forms.  Simply, it is not possible to host Windows Forms.  Of course there are exceptions but basically Windows Forms are designed to run on a desktop not a hosted service.  I would say it is unlikely.

    IMHO, the first step is learning how this Sage thing works.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 15, 2018 1:27 PM
  • User-1458727574 posted

    Yup, I'm with you there. Thanks for your help.

    Friday, June 15, 2018 1:51 PM