Trying to bind configuration: System.ComponentModel.TypeConverter can't be loaded

我们两清 提交于 2020-02-24 11:24:18

问题


I am trying to use ASP.NET Core configuration (specifically Microsoft.Extensions.Configuration.Json) in a console application. When I call IConfigurationRoot.Bind() it throws a FileNotFound exception for the assembly System.ComponentModel.TypeConverter.

To my knowledge TypeConverter is in the System.ComponentModel namespaces in the System assembly, not the fictitious System.ComponentModel.TypeConverter assembly.

This appears to be a bug. Or am I missing something?

I'm targeting .NET 4.5.2, have referenced System, and have the following NuGet packages installed:

<package id="Microsoft.Extensions.Configuration" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.Configuration.Binder" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.Configuration.Json" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.FileProviders.Physical" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.FileSystemGlobbing" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0" targetFramework="net452" />

Is there a workaround or additional steps?

This also does not work:

ConfigurationBinder.Bind(config, myconfig);

It does not seem to matter whether my JSON represents string properties or a struct such as a TimeSpan.


回答1:


I've been used to TypeConverter being in System. I poked around NuGet and found there is indeed an assembly, System.ComponentModel.TypeConverter as part of .NET Core. Installing that package fixed my problem.



来源:https://stackoverflow.com/questions/38773481/trying-to-bind-configuration-system-componentmodel-typeconverter-cant-be-loade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!