Hi I try use WindsorContainer in my WPF app. I downloaded dll-s from this site: http://stw.castleproject.org/Windsor.MainPage.ashx. WPF is based on .NET Framework 4.0 so I add
- Castle.Core and
- Castle.Windsor for .NET 4.0.
I my project I refer this Caliburn dll-s:
- Caliburn.Castle
- Caliburn.Core
- Caliburn.Presentation开发者_Go百科Framework all for .NET 4.0
and also Microsoft.Practices.ServiceLocator is for version 2.0.
My code is look like this:
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>
When I try compile my project I get this error:
Could not load file or assembly 'Castle.Windsor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
StakTrace:
*at Spirit_Messenger.App.CreateContainer() at Caliburn.PresentationFramework.ApplicationModel.CaliburnApplication..ctor() at Spirit_Messenger.App..ctor() in C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_Messenger\App.xaml.cs:line 15 at Spirit_Messenger.App.Main() in C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_Messenger\obj\x86\Release\App.g.cs:line 50 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()*
I am newbie in WPF / IoC-DI where can be problem. I am so confuse. Thank for help.
This is sometimes a pain. Use ILDASM to check the version of the Castle that those other DLLs need and I bet they are different from the ones you have.
I solved my problem by downloading and recompiling the open source code against the version I had.
Using ILDASM to see references of an assembly:
- Open the DLL with ILDASM
- Extend the tree
- Click on the manifest
At the top of the page you can see the references. For example here is a snippet of assemblies for FluentNHibernate.DLL:
// Metadata version: v2.0.50727 .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 2:0:0:0 } .assembly extern NHibernate { .publickeytoken = (AA 95 F2 07 79 8D FD B4 ) // ....y... .ver 3:0:0:2001 } .assembly extern System.Core { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 3:5:0:0 } .assembly extern System.Xml { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 2:0:0:0 } .assembly extern System.Data { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 2:0:0:0 } .assembly extern System { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 2:0:0:0 } .assembly extern Iesi.Collections { .publickeytoken = (AA 95 F2 07 79 8D FD B4 ) // ....y... .ver 1:0:1:0 } .assembly extern System.Configuration { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....: .ver 2:0:0:0 }
精彩评论