Cannot load specific mscorlib

Topics: Prism v4 - WPF 4
Jul 12, 2013 at 10:58 AM
I'm getting this exception but I have no clue why it started.
It seems to be related to a specific version but I've done everything I can think of to prevent this.

Code fails in the bootstrapper run method.

{"Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"}


at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetEnumerator()
at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__14
2.MoveNext()
at Microsoft.Practices.Prism.MefExtensions.DefaultPrismServiceRegistrar.GetRequiredPrismPartsToRegister(AggregateCatalog aggregateCatalog) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.MefExtensions\DefaultPrismServiceRegistrar.cs:line 54
at Microsoft.Practices.Prism.MefExtensions.DefaultPrismServiceRegistrar.RegisterRequiredPrismServicesIfMissing(AggregateCatalog aggregateCatalog) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.MefExtensions\DefaultPrismServiceRegistrar.cs:line 37
at Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.RegisterDefaultTypesIfMissing() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.MefExtensions\MefBootstrapper.cs:line 188
at Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.Run(Boolean runWithDefaultConfiguration) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.MefExtensions\MefBootstrapper.cs:line 82
at Microsoft.Practices.Prism.Bootstrapper.Run() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Bootstrapper.cs:line 77
at SGS_LA_Shell.Application.RunInDebugMode() in C:\Users\Robert_Powell\documents\visual studio 2010\Projects\SGS_LA_Shell\SGS_LA_Shell\App.xaml.vb:line 17
at SGS_LA_Shell.Application.OnStartup(StartupEventArgs e) in C:\Users\Robert_Powell\documents\visual studio 2010\Projects\SGS_LA_Shell\SGS_LA_Shell\App.xaml.vb:line 8
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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
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.LegacyInvokeImpl(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.Threading.Dispatcher.Run()
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 SGS_LA_Shell.Application.Main() in C:\Users\Robert_Powell\documents\visual studio 2010\Projects\SGS_LA_Shell\SGS_LA_Shell\obj\x86\Debug\Application.g.vb:line 65
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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Jul 12, 2013 at 4:08 PM
Hi,

Based on my understanding, the System.Windows.dll is related to Silverlight and not WPF. Therefore, referencing a Silverlight project in your WPF application could be the cause of the issue. Remember that you can't reference Silverlight projects in WPF. If this is not the case, you could try one of the followings too:

  • Clear the reference to the System.Windows assembly and reference it again.
  • Check the GAC to see if System.Windows is registered. If not, you will have to register it manually to the GAC.
Hope this helps,

Federico Martinez
http://blogs.southworks.net/fmartinez
Jul 13, 2013 at 12:55 PM
Hi Frederico and thanks for the reply. Actually you are right but the circumstances are odd.

I'm using VS 2010 at work to create an application using Prism. The Prism templates dont work on VS 2012 so i'm sticking with that for the moment.

I used VS 2012's version of Blend to create an animation and when I copy pasted the XAML into my VS 2010 project the project utterly died in the manner shown above. Worse than that, even when I remove the offending module and try to recompile, it seems that something has changed in the project such that this reference is fixed and will not go away. This means that the project will never run again without essentially being reconstructed from scratch. (new project and import all the files)

One big problem is that my employer insists on using VB which is not at all my cup of tea and the way it manages its references are not as evident as for a C# project.

Right now I have decided not to use Blend 2012 in the project.

Bob Powell.
Developer
Jul 15, 2013 at 8:28 PM
Hi Bob,

There might be some assemblies still referenced in you solution that are targeting the System.Windows.dll assembly by themselves and thus, producing this error to be thrown. Please check all the references of your solution to ensure that there is not other Silverlight library (or Blend library for Silverlight) referenced.

Regards,

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