无法加载文件或程序集 Castle.Windsor

发布于 2024-10-06 17:13:17 字数 3052 浏览 0 评论 0原文

您好,我尝试在我的 WPF 应用程序中使用 WindsorContainer。我从以下站点下载了 dll-s:http://stw.castleproject.org/Windsor.MainPage。 ashx。 WPF 基于 .NET Framework 4.0,因此我

  1. 添加了Castle.Core 和
  2. 为 .NET 4.0

Castle.Windsor。在我的项目中,我引用了这个 Caliburn dll-s:

  1. Caliburn.Castle
  2. Caliburn.Core
  3. 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:

*at 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 中的 Spirit_Messenger.App..ctor() 处:第 15 行 在 C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_Messenger\obj\x86\Release\App.g.cs 中的 Spirit_Messenger.App.Main():第 50 行 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,String[] args) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,字符串 [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart()*

我是 WPF / IoC-DI 的新手,可能会出现问题。我很困惑。感谢您的帮助。

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

  1. Castle.Core and
  2. Castle.Windsor for .NET 4.0.

I my project I refer this Caliburn dll-s:

  1. Caliburn.Castle
  2. Caliburn.Core
  3. Caliburn.PresentationFramework 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┊风居住的梦幻卍 2024-10-13 17:13:17

这有时是一种痛苦。使用 ILDASM 检查其他 DLL 所需的 Castle 版本,我敢打赌它们与您拥有的版本不同。

我通过下载并根据我拥有的版本重新编译开源代码解决了我的问题。


使用 ILDASM 查看程序集的引用:

  • 使用 ILDASM 打开 DLL
  • 扩展树
  • 单击清单
  • 在页面顶部,您可以看到引用。例如,下面是 FluentNHibernate.DLL 的程序集片段:

    // 元数据版本:v2.0.50727
    .Assembly 外部 mscorlib
    {
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
    .ver 2:0:0:0
    }
    .Assembly 外部 NHibernate
    {
    .publickeytoken = (AA 95 F2 07 79 8D FD B4 ) // ....y...
    .ver 3:0:0:2001
    }
    .Assembly 外部系统.Core
    {
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
    .ver 3:5:0:0
    }
    .Assembly 外部系统.Xml
    {
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
    .ver 2:0:0:0
    }
    .Assembly 外部系统.Data
    {
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
    .ver 2:0:0:0
    }
    .Assembly 外部系统
    {
    .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 外部系统. 配置
    {
    .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
    .ver 2:0:0:0
    }

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
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文