祝大家心情愉快!请帮助我使用 Unity。
我的 App.config 文件包含:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<system.diagnostics>
<sources>
<source name="TraceTest" switchName="SourceSwitch"
switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="console" />
<remove name ="Default" />
</listeners>
</source>
</sources>
<switches>
<add name="SourceSwitch" value="All" />
</switches>
<sharedListeners>
<add name="console"
type="System.Diagnostics.ConsoleTraceListener"
initializeData="false"/>
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="console" />
</listeners>
</trace>
</system.diagnostics>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="ContextDownloader"/>
<namespace name="ContextDownloader.Log"/>
<namespace name="System.Diagnostics"/>
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension,
Microsoft.Practices.Unity.Interception.Configuration"/>
<container>
<extension type="Interception"/>
<register type="ILogWorker" mapTo="FileLogWorker">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="TraceBehavior"/>
</register>
<register type="TraceSource" name="interception">
<constructor>
<param name="name" type="System.String" value="TraceTest" />
</constructor>
</register>
<register type="TraceBehavior">
<constructor>
<param name="source" dependencyName="interception" />
</constructor>
</register>
</container>
</unity>
</configuration>
我在代码中从 App.config 加载配置:
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = "App.config" };
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
var container = new UnityContainer();
所以它抛出异常
未处理的异常:System.Configuration.ConfigurationErrorsException:为统一创建配置节处理程序时出错:类型名称或别名 Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension,Microsoft.Practices.Unity.Interception.Configuration 不能解决。请检查您的配置文件并验证此类型名称。
排队var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
。如何加载 Microsoft.Practices.Unity.Interception.Configuration 程序集?
有关应用程序的更多详细信息。我有控制台应用程序和库。我刚刚在我的控制台应用程序中调用了一种方法,然后所有逻辑都在库中。
感谢您对此 Microsoft.Practices.Unity.InterceptionExtension.Configuration.dll 复制到输出库的回答。你能帮我加载 system.diagnostic 部分吗?