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

后端 未结 10 1569
遥遥无期
遥遥无期 2021-02-15 05:24

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 fil
相关标签:
10条回答
  • 2021-02-15 05:52

    Again, this is an old post, but I had the following:

    VS2012 asp.net web forms app -> upgraded to VS2013

    Try to publish - get same error as OP.

    When I finally figured it out, the problem was caused by one thing:

    when I looked into the membership providers in web.config, one item was missing the connectionStringName attribute:

    bad:

    <membership defaultProvider="SomeMembershipProvider">
      <providers>
        <clear />
        <add name="SomeMembershipProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Encrypted" applicationName="SomeAppName"  />
        <add connectionStringName="SomeConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/SomeAppName" requiresUniqueEmail="false" blaw blaw blaw />
      </providers>
    </membership>
    

    good:

    <membership defaultProvider="SomeMembershipProvider">
      <providers>
        <clear />
        <add name="SomeMembershipProvider" connectionStringName="PerhapsSomeOtherConnectionString" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Encrypted" applicationName="SomeAppName"  />
        <add connectionStringName="SomeConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/SomeAppName" requiresUniqueEmail="false" blaw blaw blaw />
      </providers>
    </membership>
    

    I'm not sure why one of the connectionStringName attributes was stripped out, or even if it was ever there, but you can turn this error on and off with this one setting.

    0 讨论(0)
  • 2021-02-15 05:57

    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.

    0 讨论(0)
  • 2021-02-15 05:59

    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.

    0 讨论(0)
  • 2021-02-15 06:03

    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'.

    0 讨论(0)
提交回复
热议问题