c# - Ninject 在加载依赖项时抛出异常

标签 c# dependency-injection ninject

在开发中成功使用我的应用程序几周后,我将其发送给了我的客户。该应用程序使用 Ninject 来处理依赖项。

当我尝试在客户端机器上运行应用程序时,出现错误:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at Ninject.Infrastructure.Language.ExtensionsForAssembly.HasNinjectModules(Assembly assembly)
   at Ninject.Modules.AssemblyNameRetriever.AssemblyChecker.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter)
   at Ninject.Modules.AssemblyNameRetriever+AssemblyChecker.GetAssemblyNames(System.Collections.Generic.IEnumerable`1<System.String>, System.Predicate`1<System.Reflection.Assembly>)
   at Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(System.Collections.Generic.IEnumerable`1<System.String>, System.Predicate`1<System.Reflection.Assembly>)
   at Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(System.Collections.Generic.IEnumerable`1<System.String>)
   at Ninject.Modules.ModuleLoader.LoadModules(System.Collections.Generic.IEnumerable`1<System.String>)
   at Ninject.KernelBase..ctor(Ninject.Components.IComponentContainer, Ninject.INinjectSettings, Ninject.Modules.INinjectModule[])
   at MyApplication.Main.Application_Start()
   at MyApplication.Main..ctor()
   at MyApplication.Program.Main()

什么会导致这个异常?

框架 4.0 注入(inject) 3.0.0.0

谢谢。

最佳答案

我猜 IoC 容器 (Ninject) 正在寻找一个无法找到的程序集来反射(reflect)。也许一个程序集没有被正确地打包到您的部署中?这也可以解释为什么它可以在您的开发机器上运行,但不能在客户端机器上运行。

关于c# - Ninject 在加载依赖项时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045201/

相关文章:

c# - 线条形状和诡计

c# - 模型出现在查询字符串中的 MVC 问题

GWT-GIN 多种实现?

c# - 让最新的 Ninject 与最新的 MVC 5/Web Api 2 一起工作?

c# - 使用默认网络凭证是一个安全漏洞吗?

c# - Breeze 一对多删除 - 子实体 FK 设置为 0

java - Spring依赖注入(inject)泛型类型的用法

c# - Autofac WcfIntegration - 通过 net.tcp 通信时无法激活 WCF 客户端服务

c# - Entity Framework 对象在传递后不更新

asp.net - 蜘蛛抓取期间与事务相关的各种 NHibernate 错误