为什么这个 Unity XML 配置没有解析类型?
Why is this Unity XML Configuration not resolving the types?
我的 unity.config
中有以下 Unity XML 配置。
<?xml version="1.0" encoding="utf-8" ?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="System.Net.WebProxy, System" name="webProxy">
<constructor>
<param name="Address" value="proxy.corporate.com:8080" type="System.String"/>
<param name="BypassOnLocal" value="false" type="System.Boolean"/>
</constructor>
</register>
<register type="System.Net.Http.HttpClientHandler, System.Net.Http" name="proxyClientHandler">
<property name="Proxy">
<dependency name="webProxy"/>
</property>
<property name="PreAuthenticate" value="true"/>
<property name="UseDefaultCredentials" value="false"/>
</register>
<register type="System.Net.Http.HttpClient, System.Net.Http">
<constructor>
<param name="handler">
<dependency name="proxyClientHandler"/>
</param>
</constructor>
</register>
</container>
</unity>
从 app.config
中正确引用了配置文件。 System
和 System.Net.Http
的程序集在项目中被引用。
当我在代码中调用 UnityContainer.LoadConfiguration()
时抛出异常:
The type name or alias System.Net.WebProxy, System could not be
resolved. Please check your configuration file and verify this type
name.
可在以下链接中查看每种类型的确切详细信息:
为什么 type
的格式被抛出,据我所知(并且在其他情况下有效),type="<fully qualified type name>, <assembly name>"
?
编辑:
请注意,我尝试过将 ", <assembly name>"
添加到 type
值中,但结果是 HttpClientHandler
而不是 [=22] 引发了相同的异常=].
您尝试过 <namespace>
标签吗? Documentation
还有 CLR 类型所需的语法,我在您的 XML 中没有看到。你也可以试试看。 Documentation(此外,文档声明您需要提供诸如 public 键之类的东西,而我在指定 CLR 类型时从来不需要这样做。)
我的 unity.config
中有以下 Unity XML 配置。
<?xml version="1.0" encoding="utf-8" ?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="System.Net.WebProxy, System" name="webProxy">
<constructor>
<param name="Address" value="proxy.corporate.com:8080" type="System.String"/>
<param name="BypassOnLocal" value="false" type="System.Boolean"/>
</constructor>
</register>
<register type="System.Net.Http.HttpClientHandler, System.Net.Http" name="proxyClientHandler">
<property name="Proxy">
<dependency name="webProxy"/>
</property>
<property name="PreAuthenticate" value="true"/>
<property name="UseDefaultCredentials" value="false"/>
</register>
<register type="System.Net.Http.HttpClient, System.Net.Http">
<constructor>
<param name="handler">
<dependency name="proxyClientHandler"/>
</param>
</constructor>
</register>
</container>
</unity>
从 app.config
中正确引用了配置文件。 System
和 System.Net.Http
的程序集在项目中被引用。
当我在代码中调用 UnityContainer.LoadConfiguration()
时抛出异常:
The type name or alias System.Net.WebProxy, System could not be resolved. Please check your configuration file and verify this type name.
可在以下链接中查看每种类型的确切详细信息:
为什么 type
的格式被抛出,据我所知(并且在其他情况下有效),type="<fully qualified type name>, <assembly name>"
?
编辑:
请注意,我尝试过将 ", <assembly name>"
添加到 type
值中,但结果是 HttpClientHandler
而不是 [=22] 引发了相同的异常=].
您尝试过 <namespace>
标签吗? Documentation
还有 CLR 类型所需的语法,我在您的 XML 中没有看到。你也可以试试看。 Documentation(此外,文档声明您需要提供诸如 public 键之类的东西,而我在指定 CLR 类型时从来不需要这样做。)