publishing asp.net website give "Object reference not set to an instance of an object." error

19,531

Solution 1

This error was occurring for me when I tried to compile the project with MSBUILD - it would build fine within Visual Studio, and would even Debug in my local browser. The Publish option within VS worked, as well. But the command-line MSBUILD was causing the project to error out every time.

I managed to fix this problem in VS 2012 by opening the Property Pages on my Website, opening the 'MSBuild Options' tab, and unchecking the 'Allow this precompiled site to be updatable' option, then hitting 'save all'.

Solution 2

I had the same experience and removing the compressed flag from the solution directory tree, set the compiler working again.

Solution 3

This typically happens when a *.dll.refresh file in the bin directory points to a location that is no longer available. Deleting the *.dll.refresh files should resolve the issue.

Solution 4

I know this is an old post, but just in case someone will find this usefull:

The cause of this problem for me was the McAfee anti-virus

ASPNETCOMPILER(0,0): Error ASPRUNTIME: Object reference not set to an instance of an object

Solution 5

I had a similar problem when compiling views in MVC WebApplication. NullReferenceException was thrown only when building solution inside VS or MSBuild. Running aspnet_compiler.exe from command line was without errors.

error ASPRUNTIME: Object reference not set to an instance of an object.

[NullReferenceException]: Object reference not set to an instance of an object.
   at System.Web.Compilation.DiskBuildResultCache.CacheBuildResult(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
   at System.Web.Compilation.BuildManager.CacheBuildResultInternal(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
   at System.Web.Compilation.WebDirectoryBatchCompiler.CacheAssemblyResults(AssemblyBuilder assemblyBuilder, CompilerResults results)
   at System.Web.Compilation.WebDirectoryBatchCompiler.CompileAssemblyBuilder(AssemblyBuilder builder)
   at System.Web.Compilation.WebDirectoryBatchCompiler.<CompileNonDependentBuildProviders>b__0(AssemblyBuilder assemblyBuilder)
   at System.Web.Compilation.CompilationUtil.CompileParallel(ICollection assemblyBuilders, Action`1 action)
   at System.Web.Compilation.WebDirectoryBatchCompiler.CompileNonDependentBuildProviders(ICollection buildProviders)
   at System.Web.Compilation.WebDirectoryBatchCompiler.Process()
   at System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors)
   at System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors)
   at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
   at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
   at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
   at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
   at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCallback callback, IEnumerable`1 excludedVirtualPaths)
   at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
   at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
   at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback, Boolean forceCleanBuild)
   at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback)
   at System.Web.Compilation.Precompiler.Main(String[] args)

After a day of looking for answers on web and discovering with ProcessMonitor, I found out that it was happening when compiler tried to compile ReportService.svc file. If this file was deleted or extension renamed, everything compiled just fine. Very strange resolution fixed problem of compiling svc files. A few days ago I turned on ntfs compression on this project to save some space. And this was the only problem. When ntfs compression attribute was removed from website folder, NullReferenceException problem was resolved.

Share:
19,531
Johan
Author by

Johan

Updated on June 05, 2022

Comments

  • Johan
    Johan almost 2 years

    I am getting fed up with this error. I have search all over the web and tried every possible suggestion to this error I could find.

    1. delete app_code, build, add files back, publish. (did not work)
    2. delete temporary asp.net files (did not work)

    In the end I even tried the command line and get the following stacktrace.

    error ASPRUNTIME: Object reference not set to an instance of an object.
    
    [NullReferenceException]: Object reference not set to an instance of an object.
       at System.Web.Compilation.BuildManager.CopyPrecompiledFile(VirtualFile vfile,
     String destPhysicalPath)
       at System.Web.Compilation.BuildManager.CopyStaticFilesRecursive(VirtualDirect
    ory sourceVdir, String destPhysicalDir, Boolean topLevel)
       at System.Web.Compilation.BuildManager.CopyStaticFilesRecursive(VirtualDirect
    ory sourceVdir, String destPhysicalDir, Boolean topLevel)
       at System.Web.Compilation.BuildManager.CopyStaticFilesRecursive(VirtualDirect
    ory sourceVdir, String destPhysicalDir, Boolean topLevel)
       at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath star
    tingVirtualDir)
       at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath startingVirt
    ualDir)
       at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCallba
    ck callback)
       at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCa
    llback callback)
       at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCa
    llback callback)
       at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuil
    dManagerCallback callback, Boolean forceCleanBuild)
       at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuil
    dManagerCallback callback)
       at System.Web.Compilation.Precompiler.Main(String[] args)
    

    I used the following command line:

    aspnet_compiler.exe -p d:\code\websites\brokerweb -v / d:\code\websites\published -f -c -errorstack -u
    
  • Alexis
    Alexis almost 10 years
    If I could vote this up a thousand times I would. This was the cause for me.
  • Amit
    Amit almost 9 years
    I spend whole 2 days to resolve the issue but it worked like a charm. But still I am not sure, why 'Allow this precompiled site to be updatable' is causing this error?
  • Chase Florell
    Chase Florell almost 9 years
    My McAfee was causing this in our corp network. I had our AV guy fix it, and the issue went away. Then he went on holidays, and the AV Scanner started scanning the directory again (GPO Update). Eff Word.
  • ganjan
    ganjan almost 8 years
    where do you find this option?
  • Sam
    Sam almost 8 years
    @ganjan its in the advanced properties for the project/solution folder.
  • Jason P Sallinger
    Jason P Sallinger over 2 years
    All other proposed solutions on other pages do not work reliably; this is the only true solution.