當我使用AssemblyScanner.FromAssembliesInPath
方法時會拋出異常。使用AssemblyScanner FromAssembliesInPath方法時,如何避免使用vshost32的FileNotFoundException?
我該如何解決這個問題?我正在使用the Ninject.Extensions.Conventions extension。我正在使用一小時前從NuGet中抓取的版本。
- Ninject 2.2.1.4更新5/7/2011
- Ninject.Extensions.Conventions 2.2.0.5 5/7/2011
我使用的掃描儀裝配這樣的更新:
Kernel.Scan(x =>
{
x.FromAssembliesMatching("*.dll");
x.FromAssembliesInPath(".");
x.WhereTypeInheritsFrom(typeof(DbContext));
x.BindWithDefaultConventions();
x.InTransientScope();
});
當試圖從Visual Studio運行我的程序,此異常得到投擲:
未處理的異常:System.IO.FileNotFoundException:無法加載文件或程序集「vshost32,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a」或其某個依賴項。該系統找不到指定的文件。
x.FromAssembliesInPath(".");
這裏的整個堆棧跟蹤:
這得到由該行代碼拋出
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'vshost32, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.UnitySerializationHolder.GetRealObject(StreamingContext context)
at System.AppDomain.Load(AssemblyName assemblyRef)
at Ninject.Extensions.Conventions.AssemblyScanner.<FindAssemblies>d__10.MoveNext() in c:\Projects\Ninject\Maintenance2.2\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\AssemblyScanner.cs:line 238
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Ninject.Extensions.Conventions.AssemblyScanner.From(IEnumerable`1 assemblies, Predicate`1 filter) in c:\Projects\Ninject\Maintenance2.2\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\AssemblyScanner.cs:line 300
at Ninject.Extensions.Conventions.AssemblyScanner.FromAssembliesInPath(String path, Predicate`1 assemblyFilter) in c:\Projects\Ninject\Maintenance2.2\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\AssemblyScanner.cs:line 325
at Ninject.Extensions.Conventions.AssemblyScanner.FromAssembliesInPath(String path) in c:\Projects\Ninject\Maintenance2.2\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\AssemblyScanner.cs:line 312
at (Line for my code, `x.FromAssembliesInPath(".");`)
at Ninject.Extensions.Conventions.ExtensionsForIKernel.Scan(IKernel kernel, Action`1 scan) in c:\Projects\Ninject\Maintenance2.2\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\ExtensionsForIKernel.cs:line 43
at (Line for my code, `Kernel.Scan(x =>`)
at Ninject.Modules.NinjectModule.OnLoad(IKernel kernel) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Modules\NinjectModule.cs:line 60
at Ninject.KernelBase.Load(IEnumerable`1 modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:line 222
at Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:line 102
at Ninject.KernelBase..ctor(INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:line 57
at Ninject.StandardKernel..ctor(INinjectModule[] modules) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\StandardKernel.cs:line 31
at (Line for my code, `using(IKernel kernel = new StandardKernel(new SomeModule()))`)
避免這種臭名昭着的異常的方法是返回一個枚舉值,而不是:http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx –
我同意。如果你沒有幽默感,那麼請忽略任何關於dailywtf的鏈接。 –
@Windowsprogrammer:哦,哈哈!我完全摒棄了這一點。感謝您的鏈接,將刪除評論:) –