asp.net 构建成功但发布失败并出现 System.OutOfMemoryException 错误

Posted

技术标签:

【中文标题】asp.net 构建成功但发布失败并出现 System.OutOfMemoryException 错误【英文标题】:asp.net build success but publish failed with System.OutOfMemoryException error 【发布时间】:2021-09-23 12:54:48 【问题描述】:

我设法构建了应用程序,但是在尝试发布(发布方法 = 文件系统)时,它遇到了下面的错误。有时我设法发布,但大多数时候会因此错误而失败。 有人可以帮忙解决这个问题吗?

以下是我尝试过但不起作用的方法:-

    以管理员身份运行 VS。 发布到新文件夹。 清理、重建和发布。 删除发布配置文件并创建新配置文件。

输出信息:


2>Copying all files to temporary location below for package/publish:
2>obj\Release\AspnetCompileMerge\Source.
2>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\DevApps\MyService\obj\Release\AspnetCompileMerge\Source -u -c C:\DevApps\MyService\obj\Release\AspnetCompileMerge\TempBuildDir 
2>/global.asax(1,0): Error ASPPARSE: Exception of type 'System.OutOfMemoryException' was thrown.
2>
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

p/s:我在这个论坛上发现了一个类似的帖子,但它发布到 Azure,这与我的不同,我发布到本地文件系统。

Web.config 文件内容

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.7.2" />
      </system.Web>
  -->
  <connectionStrings>
    <add name="connstr" connectionString="EsAhekghcHDzZG3vSKGDfNbSRCTFE9NtzZqBKh/h54PqVjTpH8izjP+QkCuXQSYublNvOxcR0bEwQLW9IUlH/w==" providerName="System.Data.SqlClient" />

  </connectionStrings>
  <system.web>
    <httpCookies httpOnlyCookies="true" />
    <compilation targetFramework="4.7.2">
      <assemblies>
        <add assembly="netstandard, Version=2.0.0.0, Culture=neutral,              PublicKeyToken=cc7b13ffcd2ddd51" />
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="1048576" targetFramework="4.7.1" />
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx" defaultUrl="Default.aspx" protection="All" requireSSL="true" slidingExpiration="false" name="authCookieDBD" timeout="1" path="/" cookieless="AutoDetect" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>
    <identity impersonate="false" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Auth" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.42.0.0" newVersion="1.42.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.42.0.0" newVersion="1.42.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.42.0.0" newVersion="1.42.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Api.Gax" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.8.9.0" newVersion="1.8.9.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    <httpProtocol>
      <customHeaders>
        <add name="X-Frame-Options" value="DENY" />
        <add name="Content-Security-Policy" value="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline';style-src-elem 'self' 'unsafe-inline' https:; img-src 'self' https:;font-src 'self' 'unsafe-inline' https:" />
        <!--<add name="Content-Security-Policy" value="script-src 'unsafe-inline'"/>-->
      </customHeaders>
    </httpProtocol>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <staticContent>
      <mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
    </staticContent>
  </system.webServer>
</configuration>

【问题讨论】:

可以添加 ASP.Net 标签吗?给我们一些有关您发布的代码或操作的信息?您要发布的文件有多大? @JialeXue-MSFT 项目文件夹为 4.19 GB。我检查了发布的文件夹是 541 MB(414 个文件,37 个文件夹)。 如您所说,您可以构建它。你试过运行它吗?运行时会不会出现这个错误? 是的,可以构建可以运行,运行时没有错误。仅在发布时发生。 可以粘贴发布配置文件的代码吗?解决方案似乎遇到了瓶颈,请给我更多信息。 【参考方案1】:
    如果您可以,请尝试使用 64 位 Visual Studio。 检查您要发布的目标文件夹中的内存可用性。

【讨论】:

嗨 Rajesh,你说使用 64 位 VS 是什么意思?我检查了我的 VS exe,它位于 C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE。我在 Program Files 文件夹中找不到任何内容。目标文件夹实际上仍然在我用来编译和发布的同一台计算机上。我将发布设置为文件系统 (C:\DevApps\Publish)。我的电脑有 32gb 内存,当我发布时,内存的使用量不到内存的一半。 嗨 Angie Chuah,VS 2019 的 32gb RAM 足以用于发布,您是否验证了该驱动器中的可用空间?你能检查一下“C:\DevApps\Publish”不是共享文件夹吗? 嗨 Rajesh,C 盘还有 37GB 空间,它不是共享文件夹。 您好 Angie Chuah,尝试重新启动您的 VS,因为可能是后台并且可能正在使用某些进程。重新启动后,我们发现此类问题消失了。 实际上我昨天确实重启了几次 VS 但无法发布。现在我再试一次,可以发布!!!好吧,然后我又试了几次,又都失败了……我真的不知道出了什么问题,它可以发布几次但大多数时候都会失败……

以上是关于asp.net 构建成功但发布失败并出现 System.OutOfMemoryException 错误的主要内容,如果未能解决你的问题,请参考以下文章

ASP.NET Core 2.0 JWT 验证失败并出现“用户授权失败:(null)”错误

API ASP.NET 5“POST”成功,但出现错误“没有路由与提供的值匹配”

从 Asp.net 客户端上传大文件到 JBoss 问题

React Native:Android 构建失败并出现异常 - 安装在模拟器上

PSEXEC 通过命令提示符成功运行,但在 ASP .Net/C# 中失败

Xcode 8 构建成功但存档失败