SGEN : error : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

49 Views Asked by At

I have an ASP.NET Web API running on .NET 4.5. It is not a .NET Core application. I have integrated Swagger for my testing and version for swagger is 5.6.0.

And I am implementing Basic Authentication. So Swagger Ui show me the the option to put the user name and Password option to authorize my call in debug mode correctly with out any issue but if I try to build the application in release mode I get this error:

"SGEN : error : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."

I have implemented the IOperationFilter like below and if I comment this class and project gets build successfully in release mode but basic authentication options do not come on swagger ui.

using Swashbuckle.Swagger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;

namespace WsCICNumberHostingRest.Authentication
{
    public class BasicHttpAuthorizeOperationFilter : IOperationFilter
    {
        public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
        {
            var filterPipeline = apiDescription.ActionDescriptor.GetFilterPipeline();
            // check if authorization is required
            var isAuthorized = filterPipeline
                .Select(filterInfo => filterInfo.Instance)
                .Any(filter => filter is IAuthorizationFilter);
            // check if anonymous access is allowed
            var allowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any();

            if (isAuthorized && !allowAnonymous)
            {
                if (operation.security == null)
                    operation.security = new List<IDictionary<string, IEnumerable<string>>>();

                var auth = new Dictionary<string, IEnumerable<string>> { { "basic", Enumerable.Empty<string>() } };

                operation.security.Add(auth);
            }
        }
    }
} 

I want to know why it is not working in release mode.

0

There are 0 best solutions below