gpt4 book ai didi

c# - ASP.NET 无法解析 xml!检查文件路径

转载 作者:太空狗 更新时间:2023-10-30 00:39:27 26 4
gpt4 key购买 nike

我通过 ASP.NET MVC 4 创建了一个简单的 API:

public class ActionController : ApiController
{
[WebMethod]
public string getCommunities()
{
try
{
MethodClass method = new MethodClass();
return method.getCommunities();
}
catch(Exception ex)
{
return ex.Message.ToString();
}
}
}

试图在 Method 类中调用此方法:

public string getCommunities()
{
return "bbb";
}

但无论出于何种原因,我都会收到此错误:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">cannot parse xml! Check file path</string>

我尝试使用谷歌搜索错误,但一无所获,有人以前见过这个错误吗?我该如何解决?

最佳答案

正如评论中已经指出的那样,您在错误的地方寻找错误。 method.getCommunities() 抛出错误消息“无法解析 xml!检查文件路径”。

用谷歌搜索你的 error在我看来,您正在抛出一个自定义异常:在您的代码中搜索该字符串可能会将您指向正确的位置。

作为概念的快速证明,我更改了由 Visual Studio Web API 模板生成的标准 API。

public string Get(int id)
{
try
{
var t = 0;
var i = 1 / t;
return "bbb";
}
catch { return "ABBA"; }
}

它准确地将自定义错误消息作为 xml 字符串返回

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">ABBA</string>

关于c# - ASP.NET 无法解析 xml!检查文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35366534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com