Could not load file or assembly microsoft.practices.prism.dll

Topics: Prism v4 - WPF 4
Jun 19, 2012 at 5:47 PM
Edited Jun 19, 2012 at 5:49 PM

I am getting this error message when I start debugging:

System.IO.FileLoadException - {"Could not load file or assembly 'file:///Q:\\Projects\\MainSail\\MainSail\\bin\\Debug\\Microsoft.Practices.Prism.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"

The path is correct.  The version is correct (4.1.0.0).  The solution with associated projects was recently ported to a network drive and renamed.  A rebuild was done for the solution and all associated projects after the bin and obj files were deleted for each.  The original solution that resides on a C: drive works properly.

 

System.IO.FileLoadException was unhandled
  Message=Could not load file or assembly 'file:///Q:\Projects\MainSail\MainSail\bin\Debug\Microsoft.Practices.Prism.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
  Source=mscorlib
  FileName=file:///Q:\Projects\MainSail\MainSail\bin\Debug\Microsoft.Practices.Prism.dll
  FusionLog=""
  StackTrace:
       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.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
       at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)
       at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
       at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
       at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
       at Microsoft.Practices.Prism.Modularity.DirectoryModuleCatalog.InnerLoad()
       at Microsoft.Practices.Prism.Modularity.ModuleCatalog.Load()
       at Microsoft.Practices.Prism.Modularity.ModuleCatalog.Initialize()
       at Microsoft.Practices.Prism.Modularity.ModuleManager.Run()
       at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.InitializeModules()
       at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration)
       at Microsoft.Practices.Prism.Bootstrapper.Run()
       at MainSail.App.OnStartup(StartupEventArgs e) in Q:\Projects\MainSail\MainSail\App.xaml.cs:line 17
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, 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.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at MainSail.App.Main() in Q:\Projects\MainSail\MainSail\obj\x86\Debug\App.g.cs:line 51
       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()
  InnerException: System.NotSupportedException
       Message=An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
       StackTrace:
       InnerException:

Developer
Jun 19, 2012 at 6:51 PM

Hi,

It seems that the problem you are mentioning might be related to the one mentioned in the following blog post:

As a starting point, you could follow the instructions proposed in the message returned by the exception you posted, which states:

"An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information."

Also, you could check the path "targeted" in the reference to the library. To do this, go to the References or your application project, select the Microsoft.Practices.Prism reference and check the Path property. Based on my understanding, the Path should be the one where you installed the Prism library.

However, take into account that you could find better support regarding running solutions from network locations for example in the Visual Studio forums:

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Jun 21, 2012 at 2:33 PM

Thank you, Damian.  Enabling the switch in the config file worked.  This issue is resolved.

Apr 28, 2013 at 8:54 AM
Hi,revans611.I'm from China.I also encountered similar problems,Would you please help me.My Email:mloyung@hotmail.com ERROR: 消息: Silverlight 应用程序中未处理的错误
代码: 4004
类别: ManagedRuntimeError
消息: System.IO.FileNotFoundException: 未能加载文件或程序集“Microsoft.Practices.Prism.UnityExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。系统找不到指定的文件。
文件名:“Microsoft.Practices.Prism.UnityExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”
位于 TimberPX.App.Application_Startup(Object sender, StartupEventArgs e)
位于 MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
位于 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

行: 56
字符: 13
代码: 0
URI: http://localhost:9958/TimberPXTestPage.aspx