Wrote an application using the Newtonsoft.Json library. When you try to launch an application from Visual Studio 2015 or 2013, everything works, when you try to run on three different PCs (different versions of Windows and different system digits) outside the VS environment, everything works, but when you try to run on two different computers (they were ordered from different hosting providers) VPS KVM with Windows Server 2012 R2 x64 (.NET Framework installed) - the application cannot load the Newtonsoft.Json.dll library. The problem arises only with this library. I tried to add the library to the resources and upload them to them - the effect is the same. If you remove parts of the code responsible for working with JSON from the application (that is, remove the use of the library itself), then everything works fine everywhere.

Below is the error that occurs during startup:

 System.BadImageFormatException: НСвозмоТно Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ сборку "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" ΠΈΠ»ΠΈ ΠΎΠ΄ΠΈΠ½ ΠΈΠ· зависимых ΠΎΡ‚ Π½ΠΈΡ… ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ². ОТидалось, Ρ‡Ρ‚ΠΎ ΠΌΠΎΠ΄ΡƒΠ»ΡŒ содСрТит манифСст сборки. Имя Ρ„Π°ΠΉΠ»Π°: "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" Π² ***.***.ReadAllItemsInfo() Π² ***.Program.Main(String[] args) Π² C:\---\Program.cs:строка 55 === Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡ ΠΎ состоянии ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ привязки === Π–ΡƒΡ€Π½Π°Π»: DisplayName = Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (Fully-specified) Π–ΡƒΡ€Π½Π°Π»: Appbase = file:///C:/---/ Π–ΡƒΡ€Π½Π°Π»: Initial PrivatePath = NULL Π’Ρ‹Π·ΠΎΠ² сборки: SoketServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Π–ΡƒΡ€Π½Π°Π»: данная привязка начинаСтся Π² контСкстС Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ default. Π–ΡƒΡ€Π½Π°Π»: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ„Π°ΠΉΠ» ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ прилоТСния: C:\---\---.exe.Config. Π–ΡƒΡ€Π½Π°Π»: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ„Π°ΠΉΠ» ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ Π³Π»Π°Π²Π½ΠΎΠ³ΠΎ ΡƒΠ·Π»Π°: Π–ΡƒΡ€Π½Π°Π»: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ„Π°ΠΉΠ» ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π° ΠΈΠ· C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. Π–ΡƒΡ€Π½Π°Π»: ссылка послС примСнСния ΠΏΠΎΠ»ΠΈΡ‚ΠΈΠΊΠΈ: Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed Π–ΡƒΡ€Π½Π°Π»: ΠΏΠΎΠΏΡ‹Ρ‚ΠΊΠ° Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ Π½ΠΎΠ²ΠΎΠ³ΠΎ URL file:///C:/---/Newtonsoft.Json.DLL. Ошибка: Π½Π΅ ΡƒΠ΄Π°Π»ΠΎΡΡŒ Π·Π°Π²Π΅Ρ€ΡˆΠΈΡ‚ΡŒ установку сборки (hr = 0x80131018). ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° ΠΏΡ€Π΅ΠΊΡ€Π°Ρ‰Π΅Π½Π°. Void ReadAllItemsInfo() 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

2 answers 2

Such an error may be in case you have built a project with AnyCpu, while some of the connected libraries are built with x86 \ x64.

How to solve this problem can be found here: https://stackoverflow.com/questions/270531/how-to-determine-if-a-net-assembly-was-built-for-x86-or-x64

I also recommend checking the version of the .net framework and checking the runtime version in the config:

 <startup> <requiredRuntime version="v4.0.20506" safemode="true"/> </startup> 

Also check the bindings:

 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-xxxx" newVersion="xxxx" /> </dependentAssembly> </assemblyBinding> </runtime> 

    The answer above did not help me at all (probably because I have Sharepoint 2013, and not a separate application), it turned out that it only cost to add the assembly to the global assembly cache:

     gacutil -i Newtonsoft.Json.dll 

    The gacutil utility should be called from the Developer Command Prompt in the Visual Studio folder.