Mert
Mert

Reputation: 6582

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:

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 couldn't find any solution at Stack Overflow, so I'd like to share here for others who stuck at same problem like me.

Upvotes: 9

Views: 28695

Answers (7)

Cryptc
Cryptc

Reputation: 3595

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

Upvotes: 1

Sergio Prats
Sergio Prats

Reputation: 1213

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>

Upvotes: 0

John81
John81

Reputation: 4074

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

Upvotes: 9

Vlad
Vlad

Reputation: 1439

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

Upvotes: 1

Artur ABC
Artur ABC

Reputation: 37

I had similar problem with x86

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

Upvotes: 2

user5490895
user5490895

Reputation: 11

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

Upvotes: 1

Mert
Mert

Reputation: 6582

Run > Regedit

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\1X.0\WebProjects   

Change Use64BitIISExpress from 0 to 1 Restart Visual Studio and IISExpress.

Upvotes: 3

Related Questions