.net core NetCore 3.1 WebApi中的GraphQL给出;“不允许同步操作”;错误
我正在学习一门多站点课程“使用ASP.NET核心构建GraphQLAPI”,但似乎没有成功。运行“游乐场”时,浏览器将加载以下内容:.net core NetCore 3.1 WebApi中的GraphQL给出;“不允许同步操作”;错误,.net-core,graphql,asp.net-core-webapi,.net Core,Graphql,Asp.net Core Webapi,我正在学习一门多站点课程“使用ASP.NET核心构建GraphQLAPI”,但似乎没有成功。运行“游乐场”时,浏览器将加载以下内容: 消息“无法访问服务器” 架构无法加载 以及浏览器右侧窗格中的以下文本: {“error”:“JSON中位置0处出现意外标记”} 如果我将其作为应用程序运行(因此不是IISExpress),那么在控制台窗口中我会看到以下故障: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
- 消息“无法访问服务器”
- 架构无法加载
- 以及浏览器右侧窗格中的以下文本:
AllowSynchronousIO
选项,我这样做了,但没有效果。我也试过在IISExpress上跑步…没什么区别
以下是我的设置的一些详细信息:
.Net核心
我创建了一个ASP.NETCore3.1(3.1.6)WebAPI项目
NuGet软件包
public class ProductSchema : Schema
{
public ProductSchema(IDependencyResolver resolver) :
base(resolver)
{
Query = resolver.Resolve<ProductQuery>();
}
}
public class ProductType : ObjectGraphType<Product>
{
public ProductType()
{
Field(p => p.Sku);
}
}
- GraphQL(2.4.0)
- GraphQL.Server.Transports.AspNetCore(3.4.0)
- GraphQL.Server.Ui.playder(3.4.0)
public class ProductSchema : Schema
{
public ProductSchema(IDependencyResolver resolver) :
base(resolver)
{
Query = resolver.Resolve<ProductQuery>();
}
}
public class ProductType : ObjectGraphType<Product>
{
public ProductType()
{
Field(p => p.Sku);
}
}
使用语句
配置服务
IPProductRepository
public interface IProductRepository
{
List<Product> GetAll();
//List<Product> GetList(List<string> skus);
//Product Get(string sku);
}
public class ProductRepository : IProductRepository
{
public List<Product> GetAll()
{
return this.AllProducts;
}
//public List<Product> GetList(List<string> skus)
//{
// return this.AllProducts.Where(p => skus.Contains(p.Sku)).ToList();
//}
//public Product Get(string sku)
//{
// return this.AllProducts.FirstOrDefault(p => p.Sku.Equals(sku));
//}
private readonly List<Product> AllProducts = new List<Product>
{
new Product
{
Sku = "ABC12345"
},
new Product
{
Sku = "ABC12345"
}
}
}
终于……解决了这个问题 我有:
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.Configure(选项=>
{
options.AllowSynchronousIO=true;
});
但需要:
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.Configure(选项=>
{
options.AllowSynchronousIO=true;
});
根据您的描述,我下载了相应版本的dll并添加了代码,但我没有重现您的错误并成功执行了代码。您能否提供有关已执行代码的更详细信息?请提供IPProductRepository
、ProductRepository
和ProductSchema
的内容供我们参考。@YongqingYu,编辑了原始帖子以提供此信息。@YongqingYu,我只是将帖子简化为只有一个字符串类型的字段。@DrGiff,尽管我使用了你所有的代码,我仍然没有重现这个问题。加载项目或执行某段代码时是否会发生错误?@Yongquing,尝试加载GraphQL时出错。。。
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});