Troubleshoot ASP.NET compilation errors

2024/1/19 |

Symptoms

When you scan a ASP.NET web application or web site in Lucent Sky AVM, the scan fails with one of the following errors:

MSBuild was skipped. ASP.NET compilation failed. (-42110061)

MSBuild failed. ASP.NET compilation failed. (-42110063)

MSBuild did not produce expected output. ASP.NET compilation failed. (-42110064)

Alternatively, the scan might complete but with the following warning:

ASP.NET compilation failed. Output from MSBuild will be used instead. (41110042)

Cause

When scanning a ASP.NET web application web site, ASP.NET Compilation Tools is used to compile dynamic web pages and controls to assemblies. If errors occurred during ASP.NET compilation, the scan fails or completes partially.

Resolution

To resolve this issue, use the following methods starting with the first method below. If that does not resolve the issue, try the next method.

Method 1

Resolve errors in ASP.NET compilation logs, then scan the application again.

  • ASP.NET compilation logs contain the following error message:

      error ASPCONFIG: Could not load file or assembly '...' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    

    The web application or web site uses an assembly that is x86 only. By default, Lucent Sky AVM uses the 64-bit version of ASP.NET Compilation Tool, which cannot load a x86 only assembly. To make Lucent Sky AVM use the 32-bit version of ASP.NET Compilation Tool, Include Bitness,32 in scan arguments.

  • ASP.NET compilation logs contain the following error message:

      error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.
    

    This error commonly occurs when Lucent Sky AVM failed to correctly detect the root of the web application or web site. For web applications, specify the relative path of its project file in the source code archive as the analysis target. For example, Contoso.Web\Contoso.Web.csproj; for web sites, put its root directory in the root of the source code archive.

  • ASP.NET compilation logs contain the following error message:

      error ASPPARSE: Could not load type '...'
    

    A reference used by the web application or website is missing. Make sure all referenced assemblies exist in the bin directory of the ASP.NET web application or web site.

  • ASP.NET compilation logs contain the following message:

      error ASPRUNTIME: The current identity (NT AUTHORITY\NETWORK SERVICE) does not have write access to 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files'.
    

    Process isolation is enabled, but the NetworkService account does not have access to directories used by ASP.NET 2.0. To grant it access, run the following command as an administrator on the system running CLEAR Engine:

      C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -ga "NT AUTHORITY\NETWORK SERVICE"
    

To learn more about resolving ASP.NET compilation errors before scanning the web application or web site, see the More Information section.

Method 2

Use direct binary analysis to scan ASP.NET web applications or web sites without building them in Lucent Sky AVM. To learn more about how to use direct binary analysis, view the following article in the Lucent Sky Knowledge Base:
Scan an application using direct binary analysis

Method 3

To disable binary analysis and only use source code analysis to scan a ASP.NET web application or web site, include AnalysisEngines,20 in scan arguments.

More Information

Before scanning an ASP.NET web application or web site, use ASP.NET Compilation Tool to make sure it is free of ASP.NET compilation errors.

  1. In Windows PowerShell, navigate to %WINDIR%\Microsoft.NET\Framework\v2.0.50727 (for ASP.NET web applications and web sites running on .NET Framework 2.0 - 3.5) or %WINDIR%\Microsoft.NET\Framework\v4.0.30319 (for ASP.NET web applications or web sites running on .NET Framework 4.0 or newer).
  2. Enter the following command:

     # Replace <WebAppPath> with path to the web application
     $webAppPath = "<WebAppPath>"
     # Replace <PublishPath> with path to a temporary directory
     $publishPath = "<PublishPath>"
     .\aspnet_compiler.exe -v / -p 'C:\website-root' 'C:\website-temp-root' -f
    
  3. Resolve any error during the publication process.
  4. Repeat the previous step until no error occurred. If the publication has completed successfully, the temporary directory specified in a previous step should contain the published website. Otherwise, it should be empty.
  5. When scanning the application normally, use the content of <WebAppPath> as the source code archive; when using direct binary analysis, use the content of <PublishPath> as the source code archive.

To learn more about precompiling ASP.NET web applications or web sites, see the following articles on the Microsoft Learn website:
Precompiling Your Website (C#) and Precompiling Your Website (VB)