gpt4 book ai didi

c# - 控制台应用程序中的 windsor ioc

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:28 24 4
gpt4 key购买 nike

我正在开发一个控制台应用程序,我想将 caSTLe windsor 用于 di。我在控制台应用程序的 Main 方法中有以下代码 -

private static IWindsorContainer container;
static void Main(string[] args)
{
container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
...

这是我的配置文件 -

<configSections>
<section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
</configSections>

<castle>
<components>
<component
id="myrepository"
service="_123App.Repositories.IMyRepository, _123App"
type="_123App.Repositories.MyRepository, _123App"
/>
</components>
</castle>

当我运行该应用程序时,出现以下错误 -

Could not convert from '_123App.Repositories.MyRepository, _123App' to System.Type - Maybe type could not be found

有人知道这里会发生什么吗?我使用反射器来确保程序集名称是正确的,并且一切都在它应该在的地方。感谢您的任何想法。

编辑 - 这是整个异常堆栈跟踪 -

Castle.MicroKernel.SubSystems.Conversion.ConverterException was unhandled
Message=Could not convert from '_123App.Repositories.MyRepository, 123App._123App' to System.Type - Maybe type could not be found
Source=Castle.Windsor
StackTrace:
at Castle.MicroKernel.SubSystems.Conversion.TypeNameConverter.PerformConversion(String value, Type targetType) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\TypeNameConverter.cs:line 91
at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion(String value, Type targetType) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\DefaultConversionManager.cs:line 134
at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion[TTarget](String value) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\DefaultConversionManager.cs:line 162
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:line 196
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:line 52
at Castle.Windsor.WindsorContainer.RunInstaller() in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\Windsor\WindsorContainer.cs:line 314
at Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter interpreter) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\Windsor\WindsorContainer.cs:line 87
at _123App.Program.Main(String[] args) in C:\Users\Username\Documents\Visual Studio 2010\Projects\_123App\_123App\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

最佳答案

立即修复是确保 _123App.dll(或 _123App.exe)进入项目的输出目录。

从长远来看,不要使用 XML 并在代码中注册组件。

关于c# - 控制台应用程序中的 windsor ioc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6255184/

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