Hi,
I am using an external API with this project and so have created a new application service to handle the client calls that need to be made to the external API. When running the project and the Swagger UI page opens it is blank with a 500 Internal Server Error on the request in the network tab of browser dev tools.
The code I am using is as follows (areas omitted as it is a private API), the code works in isolation, and also worked on an old version of ASP.NET Zero with ASP.NET MVC and Angular 1.
public async Task<string> GetDocumentPreview(GetDocumentPreviewInput input)
{
using (HttpClient client = this.GetClient(input.Token))
{
var response = await client.GetAsync(string.Format("api/previews/{0}/page/{1}", input.Id, input.PageNumber));
//var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
if (response.IsSuccessStatusCode)
{
//Omitted
}
else if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
//Omitted
}
else
{
//Omitted
}
}
}
private HttpClient GetClient(string token)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("Omitted");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
if (token == null)
{
throw new UserFriendlyException("Error when authenticating request!", "Authorisation token was null, please sign in again or contact support");
}
client.DefaultRequestHeaders.Add("Token", token);
return client;
}
I have noticed that if I create a new HttpResponseMessage manually the Swagger UI works fine, but when obtaining the HttpResponseMessage from .NET's HttpClient.GetAsync method the error is occuring.
Can Swagger not handle generating the available API methods if there is an external call with HttpClient? If so is there any way to have the call in place and still have the project run correctly as I cannot run the refresh.bat in the client with Swagger broken.
Any help is appreciated
Thanks
2 Answer(s)
-
0
Hi,
I haven't tried this scenario before. Have you checked Logs.txt file, there might be extra information about the error.
-
0
Hi,
Apologies, I wasn't aware there was a log file available Output in the log file is as follows:
DEBUG 2017-01-18 14:44:33,091 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules... DEBUG 2017-01-18 14:44:33,409 [1 ] Abp.Modules.AbpModuleManager - Found 17 ABP modules in total. DEBUG 2017-01-18 14:44:33,420 [1 ] Abp.Modules.AbpModuleManager - Loaded module: ParkLeisure.Web.Startup.ParkLeisureWebHostModule, ParkLeisure.Web.Host, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,424 [1 ] Abp.Modules.AbpModuleManager - Loaded module: ParkLeisure.Web.ParkLeisureWebCoreModule, ParkLeisure.Web.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,425 [1 ] Abp.Modules.AbpModuleManager - Loaded module: ParkLeisure.ParkLeisureApplicationModule, ParkLeisure.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,425 [1 ] Abp.Modules.AbpModuleManager - Loaded module: ParkLeisure.ParkLeisureCoreModule, ParkLeisure.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,425 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Zero.AbpZeroCoreModule, Abp.Zero, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,425 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AbpKernelModule, Abp, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,426 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Zero.Ldap.AbpZeroLdapModule, Abp.Zero.Ldap, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,426 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AutoMapper.AbpAutoMapperModule, Abp.AutoMapper, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,427 [1 ] Abp.Modules.AbpModuleManager - Loaded module: ParkLeisure.EntityFramework.ParkLeisureEntityFrameworkModule, ParkLeisure.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,427 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Zero.EntityFramework.AbpZeroEntityFrameworkModule, Abp.Zero.EntityFramework, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,428 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFramework.AbpEntityFrameworkModule, Abp.EntityFramework, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,428 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AspNetCore.AbpAspNetCoreModule, Abp.AspNetCore, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,429 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Web.AbpWebCommonModule, Abp.Web.Common, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,430 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Zero.AspNetCore.AbpZeroAspNetCoreModule, Abp.Zero.AspNetCore, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,430 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Web.SignalR.AbpWebSignalRModule, Abp.Web.SignalR, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,430 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Runtime.Caching.Redis.AbpRedisCacheModule, Abp.RedisCache, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,431 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Hangfire.AbpHangfireModule, Abp.HangFire, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:33,436 [1 ] Abp.Modules.AbpModuleManager - 17 modules loaded. DEBUG 2017-01-18 14:44:33,953 [1 ] o.Configuration.LanguageManagementConfig - Converted Abp (Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource) to MultiTenantLocalizationSource DEBUG 2017-01-18 14:44:33,953 [1 ] o.Configuration.LanguageManagementConfig - Converted AbpZero (Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource) to MultiTenantLocalizationSource DEBUG 2017-01-18 14:44:33,953 [1 ] o.Configuration.LanguageManagementConfig - Converted ParkLeisure (Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource) to MultiTenantLocalizationSource DEBUG 2017-01-18 14:44:33,953 [1 ] o.Configuration.LanguageManagementConfig - Converted AbpWeb (Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource) to MultiTenantLocalizationSource DEBUG 2017-01-18 14:44:34,976 [1 ] EntityFramework.AbpEntityFrameworkModule - Registering DbContext: ParkLeisure.EntityFramework.ParkLeisureDbContext, ParkLeisure.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DEBUG 2017-01-18 14:44:36,033 [1 ] Abp.Localization.LocalizationManager - Initializing 4 localization sources. DEBUG 2017-01-18 14:44:36,042 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Abp DEBUG 2017-01-18 14:44:36,050 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpZero DEBUG 2017-01-18 14:44:36,058 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: ParkLeisure DEBUG 2017-01-18 14:44:36,058 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpWeb DEBUG 2017-01-18 14:44:36,162 [1 ] Abp.BackgroundJobs.BackgroundJobManager - Start background worker: Abp.BackgroundJobs.BackgroundJobManager DEBUG 2017-01-18 14:44:36,233 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Found 28 classes define auto mapping attributes DEBUG 2017-01-18 14:44:36,233 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Web.Models.TokenAuth.ExternalLoginProviderInfoModel DEBUG 2017-01-18 14:44:36,237 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Sessions.Dto.TenantLoginInfoDto DEBUG 2017-01-18 14:44:36,237 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Sessions.Dto.UserLoginInfoDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Organizations.Dto.OrganizationUnitDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Organizations.Dto.OrganizationUnitUserListDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Notifications.Dto.NotificationSubscriptionWithDisplayNameDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.MultiTenancy.Dto.TenantEditDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.MultiTenancy.Dto.TenantListDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Localization.Dto.ApplicationLanguageEditDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Localization.Dto.ApplicationLanguageListDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Friendships.Dto.FriendDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Editions.Dto.EditionEditDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Editions.Dto.EditionListDto DEBUG 2017-01-18 14:44:36,238 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Editions.Dto.FlatFeatureDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Chat.Dto.ChatMessageDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Chat.Dto.ChatUserDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Chat.Dto.ChatUserWithMessagesDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Users.Profile.Dto.CurrentUserProfileEditDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Users.Dto.UserListDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Users.Dto.UserLoginAttemptDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Roles.Dto.RoleEditDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Roles.Dto.RoleListDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Permissions.Dto.FlatPermissionDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Permissions.Dto.FlatPermissionWithLevelDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Accounts.Dto.CurrentTenantInfoDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Auditing.Dto.AuditLogListDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Authorization.Users.Dto.UserListDto+UserListRoleDto DEBUG 2017-01-18 14:44:36,239 [1 ] Abp.AutoMapper.AbpAutoMapperModule - ParkLeisure.Friendships.Cache.FriendCacheItem INFO 2017-01-18 14:44:37,637 [1 ] pendencyInjection.DataProtectionServices - User profile is available. Using 'C:\Users\samc\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. DEBUG 2017-01-18 14:44:40,368 [1 ] soft.AspNetCore.Hosting.Internal.WebHost - Hosting starting DEBUG 2017-01-18 14:44:40,548 [1 ] soft.AspNetCore.Hosting.Internal.WebHost - Hosting started DEBUG 2017-01-18 14:44:40,704 [libuv] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HL1VM24BPDM6" started. DEBUG 2017-01-18 14:44:40,705 [libuv] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HL1VM24BPDM5" started. INFO 2017-01-18 14:44:40,832 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:22742/ INFO 2017-01-18 14:44:40,833 [4 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 DEBUG http://localhost:22742/ 0 DEBUG 2017-01-18 14:44:40,959 [4 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HL1VM24BPDM6" completed keep alive response. INFO 2017-01-18 14:44:40,972 [4 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 151.5702ms 200 DEBUG 2017-01-18 14:44:41,009 [9 ] NetCore.StaticFiles.StaticFileMiddleware - The request path / does not match a supported file type ERROR 2017-01-18 14:44:41,290 [9 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HL1VM24BPDM5": An unhandled exception was thrown by the application. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeAssembly.get_DefinedTypes() at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.GetControllerTypes() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.BuildModel() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.GetDescriptors() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context) at Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.GetCollection() at Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.get_ActionDescriptors() at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.GetTreeRouter() at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.RouteAsync(RouteContext context) at Microsoft.AspNetCore.Routing.RouteCollection.<RouteAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at ParkLeisure.Web.MultiTenancy.TenantIdAccessorApplicationBuilderExtensions.<>c.<<UseTenantIdAccessorInitialization>b__0_0>d.MoveNext() in C:\Development\ParkLeisure\Server\src\ParkLeisure.Web.Core\MultiTenancy\TenantIdAccessorApplicationBuilderExtensions.cs:line 20 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext() DEBUG 2017-01-18 14:44:41,300 [9 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HL1VM24BPDM5" completed keep alive response. INFO 2017-01-18 14:44:41,300 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 491.2847ms 500
Thanks
Edit: Found the problem, there was a missing reference. I never realised because there were no errors during build