gpt4 book ai didi

.net - Autofixture 奇怪的错误

转载 作者:行者123 更新时间:2023-12-03 19:48:40 29 4
gpt4 key购买 nike

我遇到了这个错误。

Ploeh.AutoFixture.Kernel.IllegalRequestException : A request for an IntPtr was detected. This is an unsafe resource that will crash the process if used, so the request is denied. A common source of IntPtr requests are requests for delegates such as Func or Action. If this is the case, the expected workaround is to Customize (Register or Inject) the offending type by specifying a proper creational strategy.

这是我的测试代码。我正在使用 autofac,其中一个依赖项是聚合服务。

var fixture = new Fixture().Customize(new AutoMoqCustomization());

var moq = new Mock<ITaskReadService>();
moq.Setup(x => x.GetFormItems(1)).Returns(GetDataTable());

IIcpServiceAggregate aggregate = _container.Resolve<IIcpServiceAggregate>();

fixture.Freeze(aggregate);
fixture.Freeze(moq.Object);

var c = fixture.CreateAnonymous<TaskController>();

最佳答案

假设 TaskController 是一个 ASP.NET MVC 3 Controller ,您应该能够通过执行以下操作来解决这个特定问题:

fixture.Customize<ViewDataDictionary>(c =>
c.Without(vdd => vdd.ModelMetadata));

因为 ViewDataDictionary.ModelMetadata 是一种 Func(记不清是哪一种)。

OOB support for delegates is coming in a future version of AutoFixture .

关于.net - Autofixture 奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6582711/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com