c# - 无法在 VS 2019 中调试方法,
问题描述
我无法调试我的项目的客户端。每次我在方法中的任何位置设置断点,当我从 UI 输入方法时,它都会带我回到 VS 并告诉我Unable to retrieve source content (Unable to retrieve source content)
。我在整个互联网上查看了是否有人在调试时在 blazor web 程序集方面有过这种经验并且无法找到解决方案。我什至尝试tools -> options -> debugging
从下图中取消选中蓝色箭头并尝试再次调试,但它并没有解决我的问题。我尝试检查下图中的红色箭头,但仍然没有解决我的问题。我不知道为什么它突然停止让我调试并返回这些错误。当我检查页面时,它显示了我Could not load content for https://localhost:5001/FileReaderComponent.js.map
. 请看下面的图片。我将附上我的客户端项目,以便您了解我所拥有的。有没有人有一个可以让我调试的解决方案?
launchsettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:27123",
"sslPort": 44340
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ClientSide": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5011;http://localhost:5012",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
index.razor
@page "/"
<h1>Upload File!</h1>
<UploadFile />
UploadFile.razor
<div class="row">
<div class="col-4">
<div class="form-group">
<input type="file" @ref="inputReference" @onchange="async () => await OpenFile()" />
<ul>
<li>File Name: @fileName</li>
<li>Size: @size</li>
<li>Type: @type</li>
</ul>
</div>
<button class="btn btn-block btn-success" @onclick="async () => await UploadFileSelected()">Upload File</button>
@if (!String.IsNullOrWhiteSpace(message))
{
<div class="alert alert-success"> File has been sucessfully uploaded!</div>
}
</div>
</div>
UploadFile.razor.cs
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Tewr.Blazor.FileReader;
namespace ClientSide.Shared
{
public partial class UploadFile
{
[Inject]
public HttpClient _httpClient { get; set; }
[Inject]
public IFileReaderService fileReader { get; set; }
public ElementReference inputReference { get; set; }
public String message = String.Empty;
public String fileName = String.Empty;
public String type = String.Empty;
public String size = String.Empty;
public Stream fileStream;
public UploadFile() { }
private async Task OpenFile()
{
// Read the files
var file = (await fileReader.CreateReference(inputReference).EnumerateFilesAsync()).FirstOrDefault();
if (file == null)
return;
// Get the info of the files
var fileInfo = await file.ReadFileInfoAsync();
fileName = fileInfo.Name;
size = $"{fileInfo.Size}b";
type = fileInfo.Type;
// memory stream ms, that has all the buffer or byte array of file contents
using (var ms = await file.CreateMemoryStreamAsync((int)fileInfo.Size))
{
fileStream = new MemoryStream(ms.ToArray());
}
}
private async Task<HttpResponseMessage> UploadFileSelected()
{
// Create the content
var content = new MultipartFormDataContent();
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
content.Add(new StreamContent(fileStream, Convert.ToInt32(fileStream.Length)), "file", fileName);
string url = "https://localhost:5001"; // this is the web api host url
var response = await _httpClient.PostAsync($"{url}/api/upload", content);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<HttpResponseMessage>(responseContent);
message = "Uploaded!";
return await Task.FromResult(result);
}
}
}
解决方案
推荐阅读
- css - 为网页上溢出的文本行添加垂直空间
- reactjs - React 弹窗安装 PWA
- android - 在 Jetpack Compose 中可视化组件树
- python - 构建`VTK` Python
- reactjs - 动画后如何在反应和打字稿中重定向到新页面
- python - CUDA 2D 矩阵位置/索引对于 dataframe.to_numpy() 和 numpy 2D 数组的行为不同
- java - Springboot GET API 在根据 Id 组合多个集合后显示来自多个集合的响应
- angular - RXJS MergeMap 没有被执行
- bazel - 在“bazel run”执行的二进制文件返回后运行动作/脚本
- c# - Unity - 在抽象类中声明布尔变量不会按预期返回