Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I am running asp.net client for wcf, but face with the Exception that I can't really cope with.

BadImageFormatException: Could not load file or assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context.


What I have tried:

Tried to remove bin folder and rebuild project as someone recommended, but nothing changed
Posted
Updated 8-Dec-20 18:18pm
Comments
Sandeep Mewara 12-Jul-20 4:07am    
Are you using IIS? Also, Which version of .NET Framework you are using?
triyul22 12-Jul-20 23:36pm    
Yes, IIS, using 3.1.0 version

1 solution

This is most commonly because your code is running as one architecture (32- or 64-bit) and a .DLL you're trying to load is a different architecture.

The C# code you're writing, by deafult, can run either 32-bit or 64-bit at runtime. In the Project Properties, Build tab, the target is going to say "AnyCPU". Change that to x86 to force your code to run as 32-bit only.

You MAY have to make a configuration chance to the Application Pool you're running your code under also expect to run 32-bit code. I can't remember off the top of my head what the exact option name is, but it's in the Advanced properties of the application pool you're using.
 
Share this answer
 
Comments
triyul22 12-Jul-20 23:16pm    
Thanks for your advice! But now browser send me another thing : HTTP Error 500.0 - ANCM In-Process Handler Load Failure
Is it related to chosen architecture?
Dave Kreskowiak 12-Jul-20 23:40pm    
Google the error message. I've never seen that message before, so that's the first thing I would do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900