问题
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