Johan
Johan

Reputation: 121

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

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

Upvotes: 12

Views: 20780

Answers (14)

aks
aks

Reputation: 526

In Visual Studio 2017, none of the solutions given here worked for me. I was able to solve the problem by the following steps:

  1. Exit Visual Studio if its running
  2. Open Visual Studio Installer from the start menu
  3. Under the Installed tab, it will display the version of Visual Studio on your computer
  4. Click the More option and select Repair
  5. After the repair operation is complete, relaunch your project in Visual Studio
  6. Now you shouldn't get this error when you click Publish

Upvotes: 1

Rohit
Rohit

Reputation: 1550

make sure you are not publishing directly on virtual directory. if yes, stop the site then publish then restart the site.

Upvotes: 0

Birke le Roux
Birke le Roux

Reputation: 3

I had the same problem when I tried to publish my webservice. The problem was that the PrecompiledApp.config file that gets created when you publish your website to a directory was some how added to my project. With that added, it caused the error.

The resolution: I deleted the file from my project tree in Visual Studio and then I was able to publish the webservice again with the precompiled settings enabled/checked.

Upvotes: 0

Robert Achmann
Robert Achmann

Reputation: 2035

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.

Upvotes: 0

Xameer
Xameer

Reputation: 31237

In my case, clearing cookies resolved the issue.

The StackTrace had mentioned some authorization and cookies thing. I opened the web application in InCognito mode (which do not persist cookie store) and found the app working.

Hope it helps somebody.

Upvotes: 0

Shoham
Shoham

Reputation: 7294

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

Upvotes: 4

Chris Stafford
Chris Stafford

Reputation: 111

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

Upvotes: 10

Bravo
Bravo

Reputation: 3441

Deleting all the *.compiled files from Bin folder of the website works for me. :)

These files are safe to delete and are created during precompilation. For more info check this MSDN link.

Upvotes: 1

Andrew McEvoy
Andrew McEvoy

Reputation: 11

I had a similar issue. The application would build and run in the IDE, but fail to publish; conking out at the 'merge dll into single assembly' stage. After researching aspnet_merge.exe I found that the issue was resolved by unchecking the 'emit debug information' checkbox in the publish options.

It may not be a 'clean' fix for the issue, but it's a workaround.

Hope this helps.

Andrew

Upvotes: 1

user3007537
user3007537

Reputation: 21

I have recently encountered this Error. As @samiz mentioned above, First of all, you need to delete all *.dll.Refresh after that build and publish your website. However, sometimes, as happen for me, when you have deleted *.dll.refresh, then publish your website, Error reminds as usual. I have done a lot of tests, but nothing changes.

I also create a new folder and copy all *.dlls which I need for my website. Next, delete all *.dll inside Bin folder then add them by one.

Finally, I re-start My PC, and then I try to publish my website. Believe me or not, it works fine and no error occurred.

Upvotes: 1

Gayanee Wijayasekara
Gayanee Wijayasekara

Reputation: 843

upgrade your Visual Studio to VS 2013. it solved the issue for me. :)

Upvotes: -2

PTBW
PTBW

Reputation: 71

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

Upvotes: 7

viliks
viliks

Reputation: 349

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.

Upvotes: 2

samiz
samiz

Reputation: 1063

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.

Upvotes: 5

Related Questions