【发布时间】:2010-12-10 15:49:23
【问题描述】:
您好,我尝试在我的 WPF 应用程序中使用 WindsorContainer。我从这个站点下载了 dll-s:http://stw.castleproject.org/Windsor.MainPage.ashx。 WPF 基于 .NET Framework 4.0 所以我添加了
- Castle.Core 和
- .NET 4.0 的 Castle.Windsor。
我的项目我参考了这个 Caliburn dll-s:
- Caliburn.Castle
- Caliburn.Core
- Caliburn.PresentationFramework 全部用于 .NET 4.0
Microsoft.Practices.ServiceLocator 适用于 2.0 版。
我的代码是这样的:
App.cs
public partial class App : CaliburnApplication
{
private IWindsorContainer _container;
public App()
{
RegisterComponents();
}
protected override IServiceLocator CreateContainer()
{
_container = new WindsorContainer();
return new WindsorAdapter(_container);
}
protected override object CreateRootModel()
{
return _container.Resolve<IShellViewModel>();
}
protected void RegisterComponents()
{
_container.Register(Component.For<IShellViewModel>()
.ImplementedBy<ShellViewModel>()
.LifeStyle.Singleton);
}
}
App.xaml
<am:CaliburnApplication
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:am="clr-namespace:Caliburn.PresentationFramework.ApplicationModel;assembly=Caliburn.PresentationFramework"
x:Class="Spirit_Messenger.App">
<am:CaliburnApplication.Resources>
</am:CaliburnApplication.Resources>
</am:CaliburnApplication>
当我尝试编译我的项目时,我得到了这个错误:
无法加载文件或程序集“Castle.Windsor,Version=2.1.0.0,Culture=neutral,PublicKeyToken=407dd0808d44fbdc”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)
StakTrace:
*在 Spirit_Messenger.App.CreateContainer() 在 Caliburn.PresentationFramework.ApplicationModel.CaliburnApplication..ctor() 在 C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_Messenger\App.xaml.cs:line 15 中的 Spirit_Messenger.App..ctor() 在 C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_Messenger\obj\x86\Release\App.g.cs:line 50 中的 Spirit_Messenger.App.Main() 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔 ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart()*
我是 WPF / IoC-DI 的新手,哪里有问题。我很困惑。感谢您的帮助。
【问题讨论】:
标签: wpf castle-windsor