.net - 异常 : ComponentActivator: could not proxy AsFactoryImplementation. <FactoryType>

标签 .net exception castle-windsor factory

我尝试使用此代码在温莎城堡中实现工厂,但它会抛出异常,如本期标题所示。我正在关注 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/

相关文章:

java - 在 Spring webflow 中捕获 "dead" session

javascript - JQuery ajax .load() 引用正确的 url

c++ - 任何想法如何使 C++ 在内核错误上抛出异常

.net - Control.EndInvoke 为异常重置调用堆栈

caSTLe-windsor - 基于基类注册类型

c# - 在 MVC 中设置 CaSTLe Windsor

c# - 如何标记依赖属性以显示在文档大纲 View 中

c# - 字符串操作。在 2 个索引之间查找字符串

c# - if((attributes and File Attributes.Hidden) == File Attributes.Hidden) { } 如何工作?

caSTLe-windsor - Envers 自定义修订监听器内的 Windsor 'Scope cache was already disposed'