An Error Occurred in PostSharp.targets on Visual Studio 2022 For Mac

168 views Asked by At

I am working on a .Net 6/AspNet Core project in VS for Mac 2022 that includes aspects and the first one is FluentValidationAspect. And when I made a unit test about that aspect, I got two errors and those are:

/Users/user/.nuget/packages/postsharp/6.10.15/build/PostSharp.targets(5,5): Error: Failed to initialize CoreCLR, HRESULT: 0x80004005 (DevFramework.Core) /Users/user/.nuget/packages/postsharp/6.10.15/build/PostSharp.targets(5,5): Error: The process "dotnet" failed with exit code 137. (DevFramework.Core)

`

using System;
using DevFramework.Core.CrossCuttingConcerns.Validation.FluentValidation;
using FluentValidation;
using FluentValidation.AspNetCore;
using PostSharp.Aspects;
using PostSharp.Serialization;

namespace DevFramework.Core.Aspects.PostSharp
{
    [PSerializable]
    public class FluentValidationAspect: OnMethodBoundaryAspect
    {
        Type _validatorType;
        public FluentValidationAspect(Type validatorType)
        {
            _validatorType = validatorType;
        }

        public override void OnEntry(MethodExecutionArgs args)
        {
            var validator = (IValidator)Activator.CreateInstance(_validatorType);
            var entityType = _validatorType.BaseType.GetGenericArguments()[0];

            var entities = args.Arguments.Where(t => t.GetType() == entityType);

            foreach(var entity in entities)
            {
                ValidatorTool.FluentValidate(validator, entity);
            }
        }
    }
}

`

`

using System;
using FluentValidation;

namespace DevFramework.Core.CrossCuttingConcerns.Validation.FluentValidation
{
    public class ValidatorTool
    {
        public static void FluentValidate(IValidator validator, object entity)
        {
            //var result = validator.Validate(entity);

            var context = new ValidationContext<object>(entity);
            var result = validator.Validate(context);

            if (result.Errors.Count>0)
            {
                throw new ValidationException(result.Errors);
            }
        }
    }
}

`

`

using System;
using DevFramework.Core.Aspects.PostSharp;
using DevFramework.Northwind.Business.Abstract;
using DevFramework.Northwind.Business.ValidationRules.FluentValidation;
using DevFramework.Northwind.DataAccess.Abstract;
using DevFramework.Northwind.Entities.Concrete;

namespace DevFramework.Northwind.Business.Concrete.Managers
{
    public class ProductManager: IProductService
    {
        private IProductDal _productDal;
        public ProductManager(IProductDal productDal)
        {
            _productDal = productDal;
        }

        public Product Add(Product product)
        {
            return _productDal.Add(product);
        }

        public List<Product> GetAll()
        {
            return _productDal.GetList();
        }

        public Product GetById(int id)
        {
            return _productDal.Get(p => p.ProductId == id);
        }

        [FluentValidationAspect(typeof(ProductValidator))]
        public Product Update(Product product)
        {
            return _productDal.Update(product);
        }
    }
}

`

**Before I ask here, I sent this question to PostSharp Service Desk. I couldn't find the exact solution. In addition, I have an intel Core i5 processor on Macbook Air 2017. **

Please help me, thanks in advance.

I tried to use PostSharp on .Net 6 project at VS 2022 For Mac. I expected to run a test. The test didn't work and I got 2 errors.

0

There are 0 answers