次のコードはバージョン3.5.1404で機能しましたが、バージョン5.0.1では機能しなくなりました。 NuGet経由で最新の参照を持っている:私は、web.configファイル内UnityのXMLマッピングの参照
:
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="ACME.Core" />
<namespace name="ACME.Core.DTO" />
<container name="Default">
<register type="IStatusRepository" mapTo="StatusRepository" />
<register type="INoteRepository" mapTo="NoteRepository" />
</container>
</unity>
エラー:
System.Configuration.ConfigurationErrorsException occurred HResult=0x80131902 Message=An error occurred creating the configuration section handler for unity: Could not load file or assembly 'Microsoft.Practices.Unity.Configuration' or one of its dependencies. The system cannot find the file specified. Source=Unity.Configuration StackTrace: at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(IUnityContainer container, String containerName)
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)
using Microsoft.Practices.Unity.Configuration;
using Unity;
namespace ACME.Core
{
public static class UnityCommon
{
static IUnityContainer _container;
/// <summary>
/// Returns the Common Unity Container from memory, reloads if not loaded first
/// </summary>
/// <param name="forceRefresh">Forces the container to be reloaded in memory</param>
/// <returns>IUnityContainer</returns>
public static IUnityContainer GetContainer(bool forceRefresh = false)
{
if (_container == null || forceRefresh)
{
_container = new UnityContainer();
_container.LoadConfiguration("Default"));
}
return _container;
}
}
}
これは、次のようなweb.configファイル内のXMLマッピングを参照
XML設定を別の方法で呼び出す必要がありますか?
私はちょうど_container.LoadConfiguration()で試しました。同じエラーが発生しました。