213

Recently I met the following exception at C# solution:

Error 2 Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

This does not depend either on my code or on the name of assembly (like Newtonsoft.Json in this case).

When I delete this dll from the solution the compiler tells about another in the same exception. So I suppose something shoud be turned off/on at my PC :)

Otiel
  • 17,975
  • 14
  • 74
  • 124
Liker777
  • 2,049
  • 4
  • 17
  • 23
  • 3
    No. Either it is a compiler error or a runtime exception. I suspect the latter. Please be more clear. – leppie Nov 25 '11 at 12:51
  • 2
    I have also faced the same exception but I managed to fix it with Thomas's solution.The problem was due to improper system shutdown due to power failure – Sandeep Jan 30 '13 at 12:26

27 Answers27

350

Looks like a corrupted assembly being referenced.

Clear both:

  1. the \bin folder of your project

  2. the temp folder (should be C:\Users\your_username\AppData\Local\Temp\Temporary ASP.NET Files in windows 7)

and see if the error still happens

Alex
  • 22,585
  • 4
  • 38
  • 71
  • 3
    alex thanks a lot for this! the second thing helped: I cleaned the temporary ASP.NEt files directory ) – Liker777 Nov 25 '11 at 13:01
  • glad to hear it works. remember to accept the answer if it helped :) – Alex Nov 25 '11 at 15:22
  • 9
    see answer by @Thomas for other locations to delete (which worked for me) – Simon_Weaver Nov 07 '12 at 21:33
  • 3
    Thanks. Clearing the user temp folder after a hard crash solved the problem for me. – Petrus Theron Jul 12 '13 at 11:07
  • After deleting the temporary files, the error was still there. I had to restart my computer then the error disappeared. – DavGarcia Nov 18 '13 at 16:04
  • 13
    %TEMP%\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files This list will grow as if you have other versions of the .NetFramework. Answer Src: http://stackoverflow.com/a/16033324/1724777 http://stackoverflow.com/a/11743430/1724777 Reason For The Prob: BLUE_SCREEN_OF_DEATH – NavaRajan Feb 10 '14 at 14:02
  • Ran into this on a MVC5 application regarding Antlr3.Runtime. Thanks. – nVentimiglia Feb 26 '14 at 15:58
  • Thank you for this. Parallels crashed while saving the project and managed to corrupt the references to the assemblies. This fixed it perfectly. – Rory McCrossan Jul 11 '14 at 14:06
  • @Alex: I am also getting the same error, I cleared the bin file of my prjoect, still the error is coming.Any help ? – Nad Nov 28 '14 at 15:11
  • @Alex Thanks !! saved me alot of time – Guy Levin Jun 27 '15 at 23:32
  • its very usefull to me, Thanks a lot –  Sep 30 '15 at 05:51
  • This in tandem with the additional locations listed in @Thomas's answer worked for me. This occurred after a power failure on my machine. – dkoch74 Oct 23 '15 at 21:22
  • It helped :) . Thank you. – Topman Sep 29 '16 at 02:57
  • I have tried all the above steps and it didn't get solved. Any other steps ? – Mac D'zen Aug 09 '21 at 13:53
287

Depending on if your are running X64 you might need to clean up a couple more spots. Just cleaning up my user directory was not enough.

  1. %TEMP%\Temporary ASP.NET Files
  2. C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
  3. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  4. C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files
  5. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

This list will grow as if you have other versions of the framework installed.

Thomas
  • 3,522
  • 3
  • 19
  • 22
  • 72
    you may find you need to do this if you computer has bluescreened during compilation – Simon_Weaver Nov 07 '12 at 21:34
  • Thnx!! I knew it would be some sort of corrupt cache thing. – Maarten Kieft Jan 04 '13 at 14:48
  • 2
    +1 Nicely compiled addition to the answer. This fixed it for me, thanks – Ralph Lavelle Jan 29 '13 at 02:55
  • 7
    This looks to be the solution if you are running Visual Studio as Administrator when your computer crashes or alternatively, if you are as dopey as myself, when your battery runs out. – Sav Aug 21 '13 at 01:34
  • I've bluescreened multiple times during compilation. Sometimes clearing /bin in the project works. Other times this solution works. – Jon La Marr Jan 28 '14 at 20:03
  • Had to do this on the server. This did work for me. Server just up and shut down for no apparent reason, and when it came back on, this madness. Thanks very much for your help. I didn't even have x64 but doing steps 2 & 3, as well as clearing my bin folder, and redeploying - that did the trick. – shubniggurath Feb 26 '14 at 16:53
  • I had to stop the IIS service to do this - the folders were in use by a process, and it turned out that IIS was using some of them. – Brandon Montgomery Sep 06 '14 at 13:39
  • deleting all the files from my x64 folder made it just work for the target framework of the applications. – Sid Nov 30 '14 at 16:27
  • 4
    OMG! I got over 4GB from prehistoric projects of mine in those places! Doesn't this thing ever clean up?!?! Thanks! – user2173353 Dec 01 '14 at 09:02
  • 2
    Just wanted to let you know that over 2 years on, this post is still helping people. Thanks very much. – Laurence Frost Feb 20 '15 at 18:46
  • This is definitely a more complete answer! – Orion Aug 20 '17 at 01:34
42

I had to clear

C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files

Only then did the issue get resolved.

Sachin Kainth
  • 43,353
  • 79
  • 196
  • 295
  • 1
    This answer worked for me too, with a 64-bit Win 7 machine hosting MVC 4 in IIS Express – Ben H Oct 16 '13 at 14:11
13

To know what to clear for sure - add the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog (DWord set to 1).

Then you will see output like below. This tells you where asp.net is attempting to load your DLLs. Clear this directory.

LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\app\AtlasAdvisor\web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL **file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3c8629f7/dfa387b6/Avanade.ViddlerNet.DLL.**
LOG: Attempting download of new URL **file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3c8629f7/dfa387b6/Avanade.ViddlerNet/Avanade.ViddlerNet.DLL**.
Yakk - Adam Nevraumont
  • 250,370
  • 26
  • 305
  • 497
voidsstr
  • 135
  • 1
  • 10
12

Clear out the temporary framework files for your project in:-

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\

andy
  • 595
  • 2
  • 8
  • 23
5

You can also clear the packages directory and allow NuGet to re-download missing packages

it solved the issue for me

megz
  • 63
  • 1
  • 5
  • ...and me, although I just removed the offending package directory. – Phil Cooper Jul 26 '15 at 14:43
  • I deleted the temps in AppData temp & c:\...\micorosoft.net\..\temp, iisreset, ... everything mensioned above. but does not work with me. Once I deleted all packages and restore it ... it works with me ... thanks a lot :D – bunjeeb Aug 30 '15 at 14:16
  • @bunjeeb it's a pleasure dude :) – megz Sep 01 '15 at 07:44
4

Delete all files from these folders .

C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files

Rakin
  • 1,225
  • 12
  • 29
3

Getting fresh set of binaries from Source control helped.

Thanks

Asif
  • 31
  • 1
3

Just clear this folder: (only windows x64)

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

pixparker
  • 2,525
  • 24
  • 19
2

Thanks Alex your second point helped me fix this.

It appears that unless you run visual studio as an administrator in Windows 7 it stores your temp files locally rather than C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files.

See following blog post: http://www.dotnetscraps.com/dotnetscraps/post/Location-of-Temporary-ASPNET-files-in-Vista-or-Windows-7.aspx

Ant
  • 338
  • 2
  • 9
2

I had the same issue here - above solutions didn't work. Problem was with ActionMailer. I ran the following uninstall and install nuget commands

uninstall-package ActionMailer
install-package ActionMailer

Resolved my problems, hopefully will help someone else.

LiamB
  • 17,715
  • 19
  • 74
  • 114
2

This can happen while referencing COM wrapper dlls. Within your Visual Studio Project, under References, select the COM wrapper dlls being referenced and ensure they have the the following property values: "Embed Interop Types": False and "Specific Version": False.

Nemo
  • 3,023
  • 1
  • 26
  • 22
  • This is a great answer and should get more upvotes. All the other answers take for granted the ASP.NET context. However, I had the same exception raised by a COM call in a simple Console application; this worked perfectly for me. Thank you sir. – alelom Mar 21 '19 at 14:38
2

I just delete my application temp data from this path

C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files

Problem resolve

Mohammad Atiour Islam
  • 4,970
  • 3
  • 41
  • 46
2

I see lot of techies have posted about clearing temporary directories of ASP .Net run-time pertaining to each and every .Net framework hosted on your machine as in this answer. But I believe we should know the clear-cut logistics as to why we need to blindly clear all of temporary working directories of all .Net frameworks. According to me, it should not be the case.

My advice would be that you should try a pin pointed directory clearing approach to resolve this issue. How would you know which directory to clear?

  1. Go to IIS and right click on your website node in left navigation pane to open the context menu. In the context menu point to Manage Application -> Advanced Settings... to open the Advanced Settings window.
  2. Check the Application Pool your website is assigned to. In my case it is DefaultAppPool as shown below:

enter image description here

  1. Now go to Application Pools node in left navigation bar in the IIS. Now check that which .Net CLR Version is being run by your app pool. In my case it is v4.0 as shown below:

enter image description here

Since the CLR version being hosted by my app pool is v4.0, so I prcisely cleared only the temporary files in the folder pertaining to ASP .NET v4.0 only as below:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

And that's it. My problem got resolved.

Lesson learnt: This is indicative of the fact that all the temporary files being used by your website aren't scattered across several directories but they are at once place being referred by your app pool. So you need to clear that specific folder only.

RBT
  • 21,293
  • 19
  • 144
  • 210
1

Clearing C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files worked for me. Thinking of automating the deletion process to avoid the issue in future.

1

If you are using SQL Server 2012's Data Tools, which uses the VS2010 shell as at May 1 2013, check your Configuration Manager settings. A server name change from Workflow to xCPWorkflow was enough to produce the exact same The parameter is incorrect (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) message.

SAinCA
  • 177
  • 10
1

You can either clean, build or rebuild your application or simply delete Temporary ASP.NET Files at C:\Users\YOUR USERNAME\AppData\Local\Temp

This works like magic. In my case i had an assembly binding issue saying Could not load file bla bla bla

you can also see solution 2 as http://www.codeproject.com/Articles/663453/Understanding-Clean-Build-and-Rebuild-in-Visual-St

Ifeanyi Chukwu
  • 2,951
  • 2
  • 27
  • 28
1

I had this problem when making controller in MVC. I changed version .net framework. The problem was solved

Hossein Hajizadeh
  • 1,247
  • 18
  • 10
0

The problem relates to the .Net runtime version of a referenced class library (expaned references, select the library and check the "Runtime Version". I had a problem with Antlr3.Runtime, after upgrading my visual studio project to v4.5. I used NuGet to uninstall Microsoft ASP.NET Web Optimisation Framework (due to a chain of dependencies that prevented me from uninstalling Antlr3 directly)

I then used NuGet to reinstall the Microsoft ASP.NET Web Optimisation Framework. This reinstalled the correct runtime versions.

Dave Russell
  • 141
  • 1
  • 7
0

In my case i wanted to compile a COM visible DLL. The problem was that an older version of this DLL was located here:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

Thus Visual Studio loaded this version instead of the newly compiled one, as it tried to register it.

dummy
  • 4,116
  • 3
  • 23
  • 35
0

Clear all files from temporary folder (C:\Users\user_name\AppData\Local\Temp\Temporary ASP.NET Files\project folder)

0

Sometimes you, also, need to clean this folder: C:\Windows\Temp\Temporary ASP.NET

Eriendel
  • 771
  • 1
  • 7
  • 19
0

I faced same error because application didn't find dependent frameworks in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\ folder. I just repair my Visual studio which added required framework in above location and it working fine.

AirCode One
  • 1,353
  • 2
  • 21
  • 42
0

In my case, changing the IISExpress port number in my project properties, solved the problem.

h3n
  • 4,628
  • 9
  • 44
  • 72
0

If anyone else out there is using the WiX toolset, I discovered that my installer project had a reference to an old project that had recently been removed from the solution. Took me a while to realize since there are a number of projects in the solution I was attempting to build and the message did not indicate which project was failing to build (and clean, which was failing as well).

rusty
  • 469
  • 1
  • 5
  • 18
0

I had users of Siemens Teamcenter 10 Client for Microsoft Office getting the same error about a different DLL. None of the other answers worked. The solution was to delete the folders in

C:\Users\%username%\AppData\Local\assembly\
Caleb Mauer
  • 655
  • 5
  • 11
0

I Had the similar issue while opening Nuget Packet manager, I removed all the temp files and build the project, it worked fine.