Could not load file or assembly

1

I have the following problem when I tried to build my website by the second time the webpage shows me this. I seek for a solution but I can't get it yet. When I load by the project the first time all the functions work well, the problem is when I turned off my computer and I start with the project by the second time.

Image with error

Server Error in '/' Application.
Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' or one of its dependencies. The system cannot find the file specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:


[FileNotFoundException: Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
   System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity) +62
   System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly() +119
   System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results) +74
   System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results) +22
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +12028905
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +52
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +341

[HttpException (0x80004005): Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +631
   System.Web.Compilation.BuildManager.CallAppInitializeMethod() +38
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +758

[HttpException (0x80004005): Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\8414c445\dc4fe894\App_global.asax.7hmxt1lb.dll' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4110.0
c#
asp.net
iis
load
.net-assembly
asked on Stack Overflow May 2, 2020 by oscar lopez • edited May 2, 2020 by oscar lopez

1 Answer

1
when I turned off my computer and I start with the project by the second time

I suspect that you turn it off - but many files did not write back on disk correctly....

Point out

The error is on Temporary ASP.NET Files directory - where asp.net automatically generates files - this is not something that have to do with your code (at least most of the time) - but the issue is with the asp.net compiler.

The general idea

Stop the programs that you use and clear the cache and temporary files, then run them again.

Steps that I follow

What step I propose to do and clear cache so IIS/asp.net/cs recompile the project. Stop the programs that makes the temporary files

  1. Check that you have free space on C drive.
  2. Close all Visual Studio programs
  3. Open "services" and stop IIS "World Wide Web Publishing Service"

Now that we have stop the main compilers we go to clear all possible cache and temporary files. For the delete use a program (like total commander) to see the hidden files too

  1. Clear the asp.net temporary directory - >C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\ all files and directory here and all Temporary ASP.NET Files that exist on your computer depend how you run the project 32/64 bit - and what version you use...

  2. Clear the temporary windows temporary directory. Type cd %temp% and there delete all the files - left the locked files that you can not delete...

  3. Clear the other temporary system windows directory that you can find on c:\windows\temp

  4. Optionally clear the .vs hidden cache directory that is on your project directory - this is only if you have issues and delays with visual studio and your project

Now let go and run again the programs

  1. Run again the "Services" and start IIS "World Wide Web Publishing Service"
  2. Run visual studio, give him a second to recompile what is needs...

Now your problem must be solved. To avoid corrupted files, check that your computer have enough free space, check the datetime on your system, and not force the shutdown of the system. Check also your hard disk for errors - open a command prompt window cmd and run chkdsk c: /f for check and fix any errors.

About temporary directories

The temporary directories are not the same on every computer. You can locate them on Control Panel | System | System Properties | Environment Variables -> look there for TEMP and TMP. When you type cd %temp% you go to your temporary directory, but many programs run under different account and for example windows have the c:/windows/temp/ directory for use.

About asp.net temporary directories. This directory by default is on c:\Windows\Microsoft.NET\Framework64\ for 64 bit, and there you locate the version and then the Temporary ASP.NET Files. This is something that you can change on web.config of your web app...

Other possible reasons

Check your event viewer and see if you have any line that indicate that the compiler crash !

Application: csc.exe Framework Version: v###### Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[])

in that case maybe you use any non asp.net net function on your global call or anything error that hang up the compiler... Check also your web.config for the section on compilers that is correct - here is an example:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" 
      type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v4.0"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>
answered on Stack Overflow May 2, 2020 by Aristos • edited May 3, 2020 by Aristos

User contributions licensed under CC BY-SA 3.0