Edvard Dumansky Edvard Dumansky - 1 month ago 6
C# Question

How to resolve "Could not load file or assembly 'Microsoft.Practices.Prism' " error?

I've been searching the past few days trying to get an error fixed in a WPF application using Prism, but haven't had any luck and thought I'd see if Stackoverflow had any ideas. Please note, I'm definitely a noob when it comes to Prism in general :)

I'm in the process of learning how to create an application using Prism, with Unity being my dependency injection container of choice. I'm trying to load modules using a modified App.config file, but I'm getting a runtime error related to the bootstrapper. The error messages will be more accurate than any explanation I can provide, so I've included the App.config file, App.xaml.cs file where the error is appearing, and the error information below.

Thank you in advance for any insight you can provide, and let me know if there's any additional information you might need!

EDIT: This file directory referenced in the error (C:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe.Config line 4) refers to the fourth line of App.config file (section name= ...). All the tutorials and references I've found are the same as what I have, but this is still the line that's causing issues it seems.

EDIT 2: The line referenced in the first edit is actually exactly the same as what's on the official Microsoft Prism guide.

EDIT 3: So I never did figure out the root of what was causing this, but in my frustration I restarted the example project I was working through and am not getting the error in the new project. Still not sure what the root of the problem was though.

EDIT 4: Just kidding, the same error is back in the new program.




App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
</configSections>

<modules>
<module assemblyFile="EmailModule.dll" moduleType="EmailService.ModuleDefinitions.Module, EmailService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="EmailModule" startupLoaded="true" />
</modules>


<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>





App.xaml.cs (error appears on the "bootstrapper.Run()" line):

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace EmailClient
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

MyBootstrapper bootstrapper = new MyBootstrapper();
bootstrapper.Run();
}
}
}





Error Message:


System.Configuration.ConfigurationErrorsException was unhandled
HResult=-2146232062
Message=An error occurred creating the configuration section handler for modules: Could not load file or assembly 'Microsoft.Practices.Prism' or one of its dependencies. The system cannot find the file specified. (C:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe.Config line 4)
Source=System.Configuration
BareMessage=An error occurred creating the configuration section handler for modules: Could not load file or assembly 'Microsoft.Practices.Prism' or one of its dependencies. The system cannot find the file specified.
Filename=C:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe.Config
Line=4
StackTrace:
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.Practices.Prism.Modularity.ConfigurationStore.RetrieveModuleConfigurationSection()
at Microsoft.Practices.Prism.Modularity.ConfigurationModuleCatalog.EnsureModulesDiscovered()
at Microsoft.Practices.Prism.Modularity.ConfigurationModuleCatalog.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 EmailClient.App.OnStartup(StartupEventArgs e) in c:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\App.xaml.cs:line 21
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 EmailClient.App.Main() in c:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\obj\Debug\App.g.cs:line 50
InnerException: System.IO.FileNotFoundException
HResult=-2147024894
Message=Could not load file or assembly 'Microsoft.Practices.Prism' or one of its dependencies. The system cannot find the file specified.
Source=System.Configuration
FileName=Microsoft.Practices.Prism
FusionLog==== Pre-bind state information ===
LOG: DisplayName = Microsoft.Practices.Prism
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.Practices.Prism | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Roger/Documents/TestPrismProject/WpfApplication1/WpfApplication1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Roger\Documents\TestPrismProject\WpfApplication1\WpfApplication1\bin\Debug\WpfApplication1.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Roger/Documents/TestPrismProject/WpfApplication1/WpfApplication1/bin/Debug/Microsoft.Practices.Prism.DLL.
LOG: Attempting download of new URL file:///C:/Users/Roger/Documents/TestPrismProject/WpfApplication1/WpfApplication1/bin/Debug/Microsoft.Practices.Prism/Microsoft.Practices.Prism.DLL.
LOG: Attempting download of new URL file:///C:/Users/Roger/Documents/TestPrismProject/WpfApplication1/WpfApplication1/bin/Debug/Microsoft.Practices.Prism.EXE.
LOG: Attempting download of new URL file:///C:/Users/Roger/Documents/TestPrismProject/WpfApplication1/WpfApplication1/bin/Debug/Microsoft.Practices.Prism/Microsoft.Practices.Prism.EXE.


StackTrace:
at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
InnerException:

Answer

The solution ended up being simple, as these things often are... I hadn't changed my App.config file's Build Action to "Resource" (can be found by clicking on the App.config file and looking at the properties section).