I do not use 'Microsoft.Practices' library,why ?

Oct 4, 2013 at 8:14 AM
Server Error in '/' Application.

Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:


Line 175: asms[i] = System.Reflection.Assembly.LoadFrom(files[i].FullName);
Line 176: }
Line 177: Bootstrapper.With.AutoMapper().Including.AssemblyRange(asms).Start();
Line 178:
Line 179: return container;

Source File: d:\Work\源码\CRM\src\Orchard\Environment\OrchardStarter.cs Line: 177

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:


[FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes) +0
System.Reflection.RuntimeAssembly.GetExportedTypes() +21
Bootstrap.Extensions.Containers.RegistrationHelper.GetTypesImplementing(Assembly assembly) +53
Bootstrap.Extensions.Containers.<>c__DisplayClass91.<GetInstancesOfTypesImplementing>b__7(Assembly a) +107
System.Collections.Generic.List
1.ForEach(Action1 action) +10758593
Bootstrap.Extensions.Containers.RegistrationHelper.GetInstancesOfTypesImplementing() +265
Bootstrap.AutoMapper.AutoMapperExtension.Run() +306
Bootstrap.Bootstrapper.Start() +112
Bootstrap.BootstrapperOption.Start() +26
Orchard.Environment.OrchardStarter.CreateHostContainer(Action
1 registrations) in d:\Work\源码\CRM\src\Orchard\Environment\OrchardStarter.cs:177
Orchard.Environment.OrchardStarter.CreateHost(Action1 registrations) in d:\Work\源码\CRM\src\Orchard\Environment\OrchardStarter.cs:191
Orchard.Web.MvcApplication.HostInitialization(HttpApplication application) in d:\Work\源码\CRM\src\Orchard.Web\Global.asax.cs:50
Orchard.WarmupStarter.<>c__DisplayClass3.<LaunchStartupThread>b__2(Object state) in d:\Work\源码\CRM\src\Orchard.WarmupStarter\Starter.cs:89

[ApplicationException: Error during application initialization]
Orchard.WarmupStarter.Starter
1.OnBeginRequest(HttpApplication application) in d:\Work\源码\CRM\src\Orchard.WarmupStarter\Starter.cs:63
Orchard.Web.MvcApplication.Application_BeginRequest() in d:\Work\源码\CRM\src\Orchard.Web\Global.asax.cs:33

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +108
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +56
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Coordinator
Oct 4, 2013 at 1:27 PM
It seems that you are running inside Orchard. Bootstrapper scans all loaded assemblies for types maybe it picked up something from Orchard.
You could try changing your statement to use IncludingOnly to prevent bootstrapper from picking other assemblies.
Bootstrapper.With.AutoMapper().IncludingOnly.AssemblyRange(asms).Start(); 
You could also try explicitely excluding EnterpriseLibrary assemblies.
Bootstrapper.Excluding.Assembly("Microsoft.Practices.EnterpriseLibrary").  .With.AutoMapper().Including.AssemblyRange(asms).Start(); 
Give it a try and let me know.

Luis
Oct 6, 2013 at 6:31 AM
orchard项目及其他类库并没有引用Microsoft.Practices.EnterpriseLibrary,编译都能通过,就是运行的时候出现上面那个错误。我现在把Microsoft.Practices.EnterpriseLibrary引入就正常运行了。我以前也出现过这样的情况,把相关dll文件引入就可以了。很奇怪。