ASP.NET Core 6 MVC application with Mudblazor not working once deployed to Azure app service using Azure Devops

huangapple go评论93阅读模式
英文:

ASP.NET Core 6 MVC application with Mudblazor not working once deployed to Azure app service using Azure Devops

问题

抱歉,以下是您提供的内容的翻译:

问题描述

我有一个解决方案,其中包含一些 Azure 函数形式的微服务,以及一些共享项目和一个 MVC6 Mudblazor Web 应用程序。

问题

当我通过 Visual Studio 2022 逐个部署所有这些组件时,一切正常。

然而,当我通过 Azure DevOps 发布管道进行部署时,一切开始变得混乱。函数部署正常。但 Web 应用程序开始表现异常。Web 应用程序正常加载,但当我尝试登录时,出现以下错误:

严重: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
处理组件时发生未处理的异常:ExpectedStartOfValueNotFound,< 路径:$ | 行号:0 | 行中的字节位置:0。

System.Text.Json.JsonException: ExpectedStartOfValueNotFound,< 路径:$ | 行号:0 | 行中的字节位置:0。
---> System.Text.Json.JsonReaderException: ExpectedStartOfValueNotFound,< 行号:0 | 行中的字节位置:0。
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader&,ExceptionResource,Byte,ReadOnlySpan1 ) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte ) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte ) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter1[[MyProject.Platform.Shared.Wrapper.Result1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse, PublicKeyToken=null]].ReadCore(Utf8JsonReader&amp;,JsonSerializerOptions,ReadStack&amp; ) 异常的内部异常堆栈结束处 at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack&amp;,JsonReaderException ) at System.Text.Json.Serialization.JsonConverter1[[MyProject.Platform.Shared.Wrapper.Result`1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse,
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task,ComponentState)

blazor.webassembly.js:1 严重: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
处理组件时发生未处理的异常:在解析值时遇到意外字符:T。路径 '',行号 0,位置 0。
Newtonsoft.Json.JsonReaderException: 在解析值时遇到意外字符:T。路径 '',行号 0,位置 0。
在 Newtonsoft.Json.JsonTextReader.ParseValue()
在 Newtonsoft.Json.JsonTextReader.Read()
在 Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
在 Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract,Boolean hasConverter)
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader,Type objectType,Boolean checkAdditionalContent)
在 Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,Type objectType)
在 Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader,Type objectType)
在 Newtonsoft.Json.JsonConvert.DeserializeObject(String value,Type type,JsonSerializerSettings settings)
在 Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value,JsonSerializerSettings settings)
在 Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value)

在 Toolbelt.Blazor.HttpClientInterceptor.InvokeAsync(HttpClientInterceptorEventHandler asyncEventHandler,HttpClientInterceptorEventArgs args)
在 Toolbelt.Blazor.HttpClientInterceptor.InvokeAfterSendAsync(HttpClientInterceptorEventArgs args)
在 Toolbelt.Blazor.HttpClientInterceptorHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
在 System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage,HttpCompletionOption,CancellationTokenSource,Boolean,CancellationTokenSource,CancellationToken )

在 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
在 Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
在 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
在 Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task,ComponentState)

资源加载失败:服务器以状态码 405(不允许的方法)响应

这是我使用的管道 YAML:

  1. trigger:
  2. - development
  3. - master
  4. pool:
  5. vmImage: 'windows-latest'
  6. variables:
  7. solution: '**/*.sln'
  8. buildPlatform: 'Any CPU'
  9. buildConfiguration: 'Debug'
  10. publishPath: '$(Build.ArtifactStagingDirectory)/publish'
  11. stages:
  12. - stage: BuildApp
  13. displayName: Build Apps
  14. jobs:
  15. - job: BuildApp
  16. displayName: Build App
  17. steps:
  18. - task: DotNetCoreInstaller@2
  19. displayName: 'Install .NET 6 SDK'
  20. inputs:
  21. version: '6.x'
  22. - task: DotNetCoreInstaller@2
  23. displayName: 'Install .NET 7 SDK'
  24. inputs:
  25. version: '7.x'
  26. - task: DotNetCoreCLI@2
  27. displayName: 'Install WebAssembly tools for .NET 6'
  28. inputs:
  29. command: 'custom'
  30. custom: 'workload'
  31. arguments: 'install wasm-tools-net6'
  32. workingDirectory: '$(Agent.ToolsDirectory)/dotnet'
  33. - task: DotNetCoreInstaller@2
  34. displayName: 'Install .NET 3 SDK'
  35. inputs:
  36. version: '3.x'
  37. - task: NuGetToolInstaller@1
  38. inputs:
  39. versionSpec: '6.5'
  40. - task: NuGetCommand@2
  41. inputs:
  42. command: 'restore'
  43. restoreSolution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
  44. feedsToUse: 'config'
  45. nugetConfigPath: '$(System.DefaultWorkingDirectory)/nuget.config'
  46. arguments: '-Parallel'
  47. - task: MSBuild@1
  48. displayName: 'BUILD!!'
  49. inputs:
  50. solution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
  51. msbuildArchitecture: 'x64'
  52. platform: 'any cpu'
  53. configuration: $(buildConfiguration)
  54. - task: DotNetCoreCLI@2
  55. inputs:
  56. command: 'build'
  57. projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
  58. arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
  59. - task: Dot
  60. <details>
  61. <summary>英文:</summary>
  62. **The setup**
  63. I have solution with quite few micro services in the form of Azure functions and a few shared projects and one MVC6 Mudblazor web app.
  64. **The Problem**
  65. When I deploy all of these components individually through Visual Studio 2022, everything works fine.
  66. However, when I deploy these through an Azure Devops release pipeline, things start going crazy. Functions deploy fine. But the Webapp starts misbehaving. The webapp loads up fine but when i try to login, I get the following errors:
  67. &gt; crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
  68. &gt; Unhandled exception rendering component: ExpectedStartOfValueNotFound, &lt; Path: $ | LineNumber: 0 | BytePositionInLine: 0.
  69. &gt;
  70. &gt; System.Text.Json.JsonException: ExpectedStartOfValueNotFound, &lt; Path: $ | LineNumber: 0 | BytePositionInLine: 0.
  71. &gt; ---&gt; System.Text.Json.JsonReaderException: ExpectedStartOfValueNotFound, &lt; LineNumber: 0 | BytePositionInLine: 0.
  72. &gt; at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader&amp; , ExceptionResource , Byte , ReadOnlySpan`1 )
  73. &gt; at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte )
  74. &gt; at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte )
  75. &gt; at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
  76. &gt; at System.Text.Json.Utf8JsonReader.Read()
  77. &gt; at System.Text.Json.Serialization.JsonConverter`1[[MyProject.Platform.Shared.Wrapper.Result`1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse, PublicKeyToken=null]].ReadCore(Utf8JsonReader&amp; , JsonSerializerOptions , ReadStack&amp; )
  78. Exception_EndOfInnerExceptionStack
  79. at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack&amp; , JsonReaderException )
  80. at System.Text.Json.Serialization.JsonConverter`1[[MyProject.Platform.Shared.Wrapper.Result`1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse,
  81. at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
  82. at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )
  83. blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
  84. Unhandled exception rendering component: Unexpected character encountered while parsing value: T. Path &#39;&#39;, line 0, position 0.
  85. Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: T. Path &#39;&#39;, line 0, position 0.
  86. at Newtonsoft.Json.JsonTextReader.ParseValue()
  87. at Newtonsoft.Json.JsonTextReader.Read()
  88. at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
  89. at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
  90. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
  91. at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
  92. at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
  93. at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
  94. at Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value, JsonSerializerSettings settings)
  95. at Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value)
  96. at
  97. at Toolbelt.Blazor.HttpClientInterceptor.InvokeAsync(HttpClientInterceptorEventHandler asyncEventHandler, HttpClientInterceptorEventArgs args)
  98. at Toolbelt.Blazor.HttpClientInterceptor.InvokeAfterSendAsync(HttpClientInterceptorEventArgs args)
  99. at Toolbelt.Blazor.HttpClientInterceptorHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  100. at System.Net.Http.HttpClient.&lt;SendAsync&gt;g__Core|83_0(HttpRequestMessage , HttpCompletionOption , CancellationTokenSource , Boolean , CancellationTokenSource , CancellationToken )
  101. at
  102. at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
  103. at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
  104. at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
  105. at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )
  106. Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
  107. This is the pipeline YAML I used:
  108. trigger:
  109. - development
  110. - master
  111. pool:
  112. vmImage: &#39;windows-latest&#39;
  113. variables:
  114. solution: &#39;**/*.sln&#39;
  115. buildPlatform: &#39;Any CPU&#39;
  116. buildConfiguration: &#39;Debug&#39;
  117. publishPath: &#39;$(Build.ArtifactStagingDirectory)/publish&#39;
  118. stages:
  119. - stage: BuildApp
  120. displayName: Build Apps
  121. jobs:
  122. - job: BuildApp
  123. displayName: Build App
  124. steps:
  125. - task: DotNetCoreInstaller@2
  126. displayName: &#39;Install .NET 6 SDK&#39;
  127. inputs:
  128. version: &#39;6.x&#39;
  129. - task: DotNetCoreInstaller@2
  130. displayName: &#39;Install .NET 7 SDK&#39;
  131. inputs:
  132. version: &#39;7.x&#39;
  133. - task: DotNetCoreCLI@2
  134. displayName: &#39;Install WebAssembly tools for .NET 6&#39;
  135. inputs:
  136. command: &#39;custom&#39;
  137. custom: &#39;workload&#39;
  138. arguments: &#39;install wasm-tools-net6&#39;
  139. workingDirectory: &#39;$(Agent.ToolsDirectory)/dotnet&#39;
  140. - task: DotNetCoreInstaller@2
  141. displayName: &#39;Install .NET 3 SDK&#39;
  142. inputs:
  143. version: &#39;3.x&#39;
  144. - task: NuGetToolInstaller@1
  145. inputs:
  146. versionSpec: &#39;6.5&#39;
  147. - task: NuGetCommand@2
  148. inputs:
  149. command: &#39;restore&#39;
  150. restoreSolution: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln&#39;
  151. feedsToUse: &#39;config&#39;
  152. nugetConfigPath: &#39;$(System.DefaultWorkingDirectory)/nuget.config&#39;
  153. arguments: &#39;-Parallel&#39;
  154. - task: MSBuild@1
  155. displayName: &#39;BUILD!!&#39;
  156. inputs:
  157. solution: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln&#39;
  158. msbuildArchitecture: &#39;x64&#39;
  159. platform: &#39;any cpu&#39;
  160. configuration: $(buildConfiguration)
  161. - task: DotNetCoreCLI@2
  162. inputs:
  163. command: &#39;build&#39;
  164. projects: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj&#39;
  165. arguments: &#39;--configuration Debug --output $(Build.ArtifactStagingDirectory)&#39;
  166. - task: DotNetCoreCLI@2
  167. displayName: &#39;Publish&#39;
  168. inputs:
  169. command: &#39;publish&#39;
  170. publishWebProjects: True
  171. projects: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj&#39;
  172. arguments: &#39;--configuration Debug --output $(Build.ArtifactStagingDirectory)&#39;
  173. zipAfterPublish: true
  174. - task: CopyFiles@2
  175. inputs:
  176. targetFolder: &#39;$(Build.ArtifactStagingDirectory)&#39;
  177. - task: PublishBuildArtifacts@1
  178. displayName: &#39;Publish Artifact: drop&#39;
  179. **The question**
  180. What am I doing wrong here?
  181. </details>
  182. # 答案1
  183. **得分**: 0
  184. 成功解决了问题。
  185. 问题出在这里:
  186. - 任务: DotNetCoreCLI@2
  187. 显示名称: '发布'
  188. 输入:
  189. 命令: 'publish'
  190. 发布Web项目: True
  191. 项目: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
  192. 参数: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
  193. 发布后进行压缩: true
  194. 当您设置`发布Web项目: True`时,"如果为真,则该任务将尝试在存储库中查找Web项目并对它们运行发布命令。Web项目可通过目录中存在web.config文件或wwwroot文件夹来识别。" - Azure DevOps信息按钮
  195. 由于最初为真,它每次都选择了Client,因为CLIENT项目有一个wwwroot文件夹。将`发布Web项目`设置为false后,您可以指定一个特定的SERVER项目。
  196. 所以,SERVER项目从未被部署。这就引起了所有这些混乱。
  197. 这是最终修复的更改:
  198. - 任务: DotNetCoreCLI@2
  199. 显示名称: '发布'
  200. 输入:
  201. 命令: 'publish'
  202. 发布Web项目: False
  203. 项目: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
  204. 参数: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
  205. 发布后进行压缩: true
  206. <details>
  207. <summary>英文:</summary>
  208. I was finally able to get it working.
  209. The issue was here:
  210. - task: DotNetCoreCLI@2
  211. displayName: &#39;Publish&#39;
  212. inputs:
  213. command: &#39;publish&#39;
  214. publishWebProjects: True
  215. projects: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj&#39;
  216. arguments: &#39;--configuration Debug --output $(Build.ArtifactStagingDirectory)&#39;
  217. zipAfterPublish: true
  218. When you give `publishWebProjects: True` &quot;If true, the task will try to find the web projects in the repository and run the publish command on them. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.&quot; - Azure devops info button
  219. Due to this being true originally, it was selecting Client every time because the CLIENT project has a wwwroot folder. With publishWebProjects set to false, you can specify a particular SERVER project.
  220. So, the SERVER project never got deployed.And that caused all of this havoc.
  221. This is the change that finally fixed it:
  222. - task: DotNetCoreCLI@2
  223. displayName: &#39;Publish&#39;
  224. inputs:
  225. command: &#39;publish&#39;
  226. publishWebProjects: False
  227. projects: &#39;$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj&#39;
  228. arguments: &#39;--configuration Debug --output $(Build.ArtifactStagingDirectory)&#39;
  229. zipAfterPublish: true
  230. </details>

huangapple
  • 本文由 发表于 2023年4月7日 03:41:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定