项目版本是Furion.Pure 4.6.7
将项目版本Furion.Oure 4.6.7,升级到版本 4.8.14后再启动项目就发生报错:
Microsoft.AspNetCore.Routing.Patterns.RoutePatternException: The route parameter name 'id' appears more than one time in the route template.
at Microsoft.AspNetCore.Routing.Patterns.RoutePatternParser.Parse(String pattern)
at Microsoft.AspNetCore.Routing.Patterns.RoutePatternFactory.Parse(String pattern)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointFactory.AddEndpoints(List1 endpoints, HashSet1 routeNames, ActionDescriptor action, IReadOnlyList1 routes, IReadOnlyList1 conventions, Boolean createInertEndpoints)
at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource.CreateEndpoints(IReadOnlyList1 actions, IReadOnlyList1 conventions)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.UpdateEndpoints()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Initialize()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.get_Endpoints()
at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.<>c.b__15_0(EndpointDataSource d)
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.Initialize()
at Microsoft.AspNetCore.Routing.DataSourceDependentCache1.Initialize() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory)
at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory) at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func1 matcherBuilderFactory)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Furion.UnifyResult.UnifyResultStatusCodesMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
⚠⚠ 必须提供完整可运行且包含错误的
Git
仓库 DEMO,DEMO 提供最简单的错误逻辑代码,否则将无法得到答复。⚠⚠
您的代码下载地址?
我使用的是Admin.NET项目,项目地址: https://gitee.com/zuohuaijun/Admin.NET.git
请提供安装的 NuGet
包版本号。
期待的结果是?
项目版本在Furion.Pure 4.6.7中可以使用,期望Furion.Pure 升级到版本 4.8.14,并能运行不报错。
感谢大神无私奉献,好人一生平安!!!
升级到 v4.8.8.15
版本,这个从早上7点就处理了,升级一下再反馈吧。。。
您好,我试过了,还是会报错,所以提交到这里:
Furion版本
报错stack
切换到项目原始版本,启动就不会报错。
那只能等你提供一个复现错误的 demo
给我了,别把完整的项目发上来。
这个错误只有一种可能,那就是自定义路由冲突了,出现了多个参数。
我用 Admin.NET 最新版测试正常,你把 Application
的动态 API 类一个一个的删,删一个如果还有问题就继续删,删到最后一个正常的类文件,那么就是这个文件出问题了,到时候把这个文件发上来。
找到问题的服务了,感谢指导!
代码如下:
public interface IBasicRepository<TAddEntity, TEditEntity>
where TAddEntity : class
where TEditEntity : class
{
Task<JsonResult> GetAllAsync();
Task<JsonResult> GetByIdAsync(long id);
Task<JsonResult> AddAsync(TAddEntity dto);
Task<JsonResult> EditAsync(TEditEntity dto);
Task<JsonResult> DelAsync(long id);
Task<JsonResult> QueryByPage(int page, int pageSize, string field, bool isDesc);
}
public class BaseService<TAddEntity, TEditEntity, Entity> : IBasicRepository<TAddEntity, TEditEntity>
where TAddEntity : class
where TEditEntity : EntityBase
where Entity : EntityBase
{
private readonly ILogger<BaseService<TAddEntity, TEditEntity, Entity>> logger;
private readonly IRepository<Entity> _repository;
public BaseService(ILogger<BaseService<TAddEntity, TEditEntity, Entity>> logger, IRepository<Entity> repository)
{
this.logger = logger;
_repository = repository;
logger.LogInformation("BaseService init");
}
[HttpPost]
public virtual async Task<JsonResult> AddAsync(TAddEntity dto)
{
var entity = dto.Adapt<Entity>();
var res = await _repository.InsertAsync(entity);
return new JsonResult(res);
}
[HttpGet]
public virtual async Task<JsonResult> DelAsync(long id)
{
var res = await _repository.DeleteAsync(id);
return new JsonResult(res);
}
[HttpPost]
public virtual async Task<JsonResult> EditAsync(TEditEntity dto)
{
// 首先找出源
var dbEntity = await _repository.FindByKeyAsync(dto.Id);
if (dbEntity is null)
{
throw new Exception("We can't find the entity you want to updated from reposiroty!");
}
dbEntity = dto.Adapt<Entity>();
var res = await _repository.UpdateAsync(dbEntity);
return new JsonResult(res);
}
[HttpGet]
public virtual async Task<JsonResult> GetAllAsync()
{
var res = await _repository.GetListAsync();
return new JsonResult(res);
}
[HttpGet]
public virtual async Task<JsonResult> GetByIdAsync(long id)
{
var res = await _repository.FindByKeyAsync(id);
return new JsonResult(res);
}
[HttpGet]
public virtual async Task<JsonResult> QueryByPage([FromQuery] int page, [FromQuery] int pageSize, [FromQuery] string field, [FromQuery] bool order)
{
var res = await _repository.GetPagedInfoListAsync(page, pageSize, field, order);
return new JsonResult(res);
}
/// <summary>
/// Route("{id:int}") 可以形成唯一的url,带有参数id约束为int
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[AllowAnonymous]
[Route("{id:int}")]
[HttpGet]
public JsonResult Hello([FromRoute] int id)
{
return new JsonResult($"hello world id is {id}!");
}
}
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 2000)]
public class DeviceCodeService : BaseService<DeviceAddDto, Device, Device>, IBasicRepository<DeviceAddDto, Device>, IDynamicApiController, ITransient
{
public DeviceCodeService(ILogger<BaseService<DeviceAddDto, Device, Device>> logger, IRepository<Device> repository) : base(logger, repository)
{
}
}
去掉这个DeviceCodeService的服务就好了
那就是这个问题了,我来测试。
实际上你这个是多此一举,不用贴 [Route("{id:int}")]
...删除即可。
注释掉下面的代码就好了 ,应该是多了特性或者方法中的Route,旧版本不报错,新版本会报错。 感谢!
/// <summary>
/// Route("{id:int}") 可以形成唯一的url,带有参数id约束为int
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[AllowAnonymous]
[Route("{id:int}")]
[HttpGet]
public JsonResult Hello([FromRoute] int id)
{
return new JsonResult($"hello world id is {id}!");
}
旧版本不报错才是 bug
....
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
已修复(实际上不是问题,应该说已支持...):https://gitee.com/dotnetchina/Furion/commit/6c6434c37124f62d64ca2371d89537273a36abff
下个版本(明天)发布。
越来越变态了,你们花样真多...,不是一般人都不敢支持...
因为之前都没有报错过,我只是测试Hello不同路由的方法,后面也没删除,留在里面了,也不报错,所以没向这里去想。独此一份的bug哈哈。
Furion是越来越好用了,配合Admin.Net,确实省事不少,很强大,不管是学习还是公司用,都不错。
后面会一直支持,把.Net做大做强,再创辉煌。
已发布最新版 v4.8.8.18
,已支持。
登录 后才可以发表评论