'Could not load file or assembly 'sapnco' or one of its dependencies. An attempt was made to load a program with an incorrect format

I have got this error while I am using SAP .NET Connector 3.0 x64. I couldn't find any solution at stackoverflow, so I d like to share here for others who stuck at same problem like me.



Solution 1:[1]

In VS 2017 I was able to resolve this by setting the Bitness to "x64" for IIS Express in the server section under the project web properties. I imagine this is similar to making the Use64BitIISExpress Regedit change in one of the other answers.

enter image description here

Solution 2:[2]

I had similar problem with x86

I set the Platform Target from "any" to "x86", in Project/Properties and fixed the problem.

Solution 3:[3]

You Can try browsing/configured your service through IIS, and set appPool .Net 4.0. I hope this solve the sapnco dll issue.

Solution 4:[4]

I had the same type of fix as the other answers, but in a slightly different spot...

I had to set the IIS App Pool to allow 32-Bit Applications:

App Pool Advanced Settings 32-Bit

Solution 5:[5]

I had similar problem with VS 2017 and AnyCPU project option.

To fix the problem I disable Prefer 32-bit checkbox in project build properties.

StartUp project properties tab

Solution 6:[6]

I was having this error when trying to connect to SAP in x64 mode I was able to solve it by modifying the App.config file to include the useLegacyV2RuntimeActivationPolicy="true" attribute in the startup section:

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John81
Solution 2 Artur ABC
Solution 3 user5490895
Solution 4 Cryptc
Solution 5 Vlad
Solution 6 Sergio Prats