gpt4 book ai didi

.net - 异常 : ComponentActivator: could not proxy AsFactoryImplementation.

转载 作者:行者123 更新时间:2023-12-01 09:02:22 24 4
gpt4 key购买 nike

我尝试使用此代码在温莎城堡中实现工厂,但它会抛出异常,如本期标题所示。我正在关注 Documentation here 的示例.请指出我哪里出错了。

using System;
using System.Windows.Forms;
using Castle.Facilities.TypedFactory;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace AsFactoryImplementation
{
interface IDummyComponnentFactory
{
IDummyComponnent creat();
void Relese(IDummyComponnent factory);
}

interface IDummyComponnent
{
void show();
}

class DummyComponnent:IDummyComponnent
{
public void show()
{
Console.WriteLine("just testing this for better performance");
}
}

class Program:WindsorContainer
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();

container.Register(Component.For<IDummyComponnent>().ImplementedBy<DummyComponnent>().Named("FirstConnection").LifeStyle.Transient
,Component.For<IDummyComponnentFactory>().AsFactory());

var val = container.Resolve<IDummyComponnent>();
val.show();

var val2 = container.Resolve<IDummyComponnentFactory>();

}
}

}

最佳答案

内部异常解释得还不够好吗?

Type AsFactoryImplementation.IDummyComponnentFactory is not visible to DynamicProxy. Can not create proxy for types that are not accessible. Make the type public, or internal and mark your assembly with [assembly:
InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]
attribute.

关于.net - 异常 : ComponentActivator: could not proxy AsFactoryImplementation. <FactoryType>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14750615/

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