lundi 30 mars 2020

Cannot make a Generic Class of Type System.Fabric.FabricServiceNotFoundException when using c# reflection

I have the following function that takes in an error and creates a class instance of ErrorType<T>

 private dynamic GenerateDynamicErrorHandler(Exception ex)
    {
        try
        {
            string typeName = ex.GetType().FullName;
            Type typeArgument = Type.GetType(typeName);
            Type genericClass = typeof(ErrorType<>);

            Type constructedClass = genericClass.MakeGenericType(typeArgument);

            dynamic created = Activator.CreateInstance(constructedClass);
            return created;
        }
        catch
        {
            throw new ReflectionException(ex.GetType().FullName);
        }
    }

Which then returns a dynamic object in the following code snippet:

 try
        {
            dynamic c = GenerateDynamicErrorHandler(ex);

            if (c.IsError())
            {
                return c.GenericResponse<ErrorDetails,AppendingErrors>(isDebug,
                    isDefaultConverter,
                    context, 
                    _errorDetailResponseFactory.CreateDefaultError(ex.Message,ex.InnerException,context.Response.StatusCode),
                    new AppendingErrors
                    {
                        Title = c.Get().Title,
                        ResultCode = c.Get().ResultCode,
                        StackTrace = ex.StackTrace

                    });
            }
            return HandleError.WithDefaultJsonConverter<ErrorDetails>(context, 
                _errorDetailResponseFactory.CreateDefaultError(ex.Message,ex.InnerException,context.Response.StatusCode));
        }
        catch(ReflectionException re)
        {
            return HandleError.WithGenericApendingJsonConverter<ErrorDetails, object>(context,
            _errorDetailResponseFactory.CreateDefaultError(ex.Message, ex.InnerException, context.Response.StatusCode), 
            new {
                reflectionError = re.Message
            });
        }

This works for all Exceptions except for System.Fabric.FabricServiceNotFoundException and I dont understand or have any clue as to why. If anyone could assist with this, it would be greatly appreciated





Aucun commentaire:

Enregistrer un commentaire