英文:
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.JsonConverter
1[[MyProject.Platform.Shared.Wrapper.Result1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse, PublicKeyToken=null]].ReadCore(Utf8JsonReader&,JsonSerializerOptions,ReadStack& ) 异常的内部异常堆栈结束处 at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack&,JsonReaderException ) at System.Text.Json.Serialization.JsonConverter
1[[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:
trigger:
- development
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
publishPath: '$(Build.ArtifactStagingDirectory)/publish'
stages:
- stage: BuildApp
displayName: Build Apps
jobs:
- job: BuildApp
displayName: Build App
steps:
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 6 SDK'
inputs:
version: '6.x'
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 7 SDK'
inputs:
version: '7.x'
- task: DotNetCoreCLI@2
displayName: 'Install WebAssembly tools for .NET 6'
inputs:
command: 'custom'
custom: 'workload'
arguments: 'install wasm-tools-net6'
workingDirectory: '$(Agent.ToolsDirectory)/dotnet'
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 3 SDK'
inputs:
version: '3.x'
- task: NuGetToolInstaller@1
inputs:
versionSpec: '6.5'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
feedsToUse: 'config'
nugetConfigPath: '$(System.DefaultWorkingDirectory)/nuget.config'
arguments: '-Parallel'
- task: MSBuild@1
displayName: 'BUILD!!'
inputs:
solution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
msbuildArchitecture: 'x64'
platform: 'any cpu'
configuration: $(buildConfiguration)
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
- task: Dot
<details>
<summary>英文:</summary>
**The setup**
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.
**The Problem**
When I deploy all of these components individually through Visual Studio 2022, everything works fine.
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:
> crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
> Unhandled exception rendering component: ExpectedStartOfValueNotFound, < Path: $ | LineNumber: 0 | BytePositionInLine: 0.
>
> System.Text.Json.JsonException: ExpectedStartOfValueNotFound, < Path: $ | LineNumber: 0 | BytePositionInLine: 0.
> ---> System.Text.Json.JsonReaderException: ExpectedStartOfValueNotFound, < LineNumber: 0 | BytePositionInLine: 0.
> at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& , ExceptionResource , Byte , ReadOnlySpan`1 )
> 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.JsonConverter`1[[MyProject.Platform.Shared.Wrapper.Result`1[[MyProject.Platform.Application.Features.Accounts.Queries.GetById.GetProjectByIdResponse, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , JsonSerializerOptions , ReadStack& )
Exception_EndOfInnerExceptionStack
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& , JsonReaderException )
at System.Text.Json.Serialization.JsonConverter`1[[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 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[Object](String value)
at
at Toolbelt.Blazor.HttpClientInterceptor.InvokeAsync(HttpClientInterceptorEventHandler asyncEventHandler, HttpClientInterceptorEventArgs args)
at Toolbelt.Blazor.HttpClientInterceptor.InvokeAfterSendAsync(HttpClientInterceptorEventArgs args)
at Toolbelt.Blazor.HttpClientInterceptorHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage , HttpCompletionOption , CancellationTokenSource , Boolean , CancellationTokenSource , CancellationToken )
at
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
This is the pipeline YAML I used:
trigger:
- development
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
publishPath: '$(Build.ArtifactStagingDirectory)/publish'
stages:
- stage: BuildApp
displayName: Build Apps
jobs:
- job: BuildApp
displayName: Build App
steps:
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 6 SDK'
inputs:
version: '6.x'
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 7 SDK'
inputs:
version: '7.x'
- task: DotNetCoreCLI@2
displayName: 'Install WebAssembly tools for .NET 6'
inputs:
command: 'custom'
custom: 'workload'
arguments: 'install wasm-tools-net6'
workingDirectory: '$(Agent.ToolsDirectory)/dotnet'
- task: DotNetCoreInstaller@2
displayName: 'Install .NET 3 SDK'
inputs:
version: '3.x'
- task: NuGetToolInstaller@1
inputs:
versionSpec: '6.5'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
feedsToUse: 'config'
nugetConfigPath: '$(System.DefaultWorkingDirectory)/nuget.config'
arguments: '-Parallel'
- task: MSBuild@1
displayName: 'BUILD!!'
inputs:
solution: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.sln'
msbuildArchitecture: 'x64'
platform: 'any cpu'
configuration: $(buildConfiguration)
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
- task: DotNetCoreCLI@2
displayName: 'Publish'
inputs:
command: 'publish'
publishWebProjects: True
projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: CopyFiles@2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
**The question**
What am I doing wrong here?
</details>
# 答案1
**得分**: 0
成功解决了问题。
问题出在这里:
- 任务: DotNetCoreCLI@2
显示名称: '发布'
输入:
命令: 'publish'
发布Web项目: True
项目: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
参数: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
发布后进行压缩: true
当您设置`发布Web项目: True`时,"如果为真,则该任务将尝试在存储库中查找Web项目并对它们运行发布命令。Web项目可通过目录中存在web.config文件或wwwroot文件夹来识别。" - Azure DevOps信息按钮
由于最初为真,它每次都选择了Client,因为CLIENT项目有一个wwwroot文件夹。将`发布Web项目`设置为false后,您可以指定一个特定的SERVER项目。
所以,SERVER项目从未被部署。这就引起了所有这些混乱。
这是最终修复的更改:
- 任务: DotNetCoreCLI@2
显示名称: '发布'
输入:
命令: 'publish'
发布Web项目: False
项目: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
参数: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
发布后进行压缩: true
<details>
<summary>英文:</summary>
I was finally able to get it working.
The issue was here:
- task: DotNetCoreCLI@2
displayName: 'Publish'
inputs:
command: 'publish'
publishWebProjects: True
projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
When you give `publishWebProjects: True` "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." - Azure devops info button
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.
So, the SERVER project never got deployed.And that caused all of this havoc.
This is the change that finally fixed it:
- task: DotNetCoreCLI@2
displayName: 'Publish'
inputs:
command: 'publish'
publishWebProjects: False
projects: '$(System.DefaultWorkingDirectory)/WebApp/MyProject.Platform.WebApp/Server/MyProject.Platform.Server.csproj'
arguments: '--configuration Debug --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论