I have a very strange problem. In my MVC 4 application I have this code to initialize StructureMap :
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
x.For<IRestHttpClient>().Use<AtlamHttpClient>().Ctor<string>().Is(Settings.AtlamServicesURL);
});
ObjectFactory.AssertConfigurationIsValid();
return ObjectFactory.Container;
}
}
that works as expected. However, I also have a .NET 4.5 Web forms application with the same basic initialization code:
public static class IoC
{
public static IContainer Configure()
{
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.AssemblyContainingType<IRestHttpClient>();
scan.AssemblyContainingType<MessagePackMediaTypeFormatter>();
});
x.For<IRestHttpClient>().Use<AtlamHttpClient>().Ctor<string>().Is(Settings.BaseServiceUrl);
/*x.SetAllProperties(y =>
{
y.OfType<IRestHttpClient>();
});*/
});
ObjectFactory.AssertConfigurationIsValid();
return ObjectFactory.Container;
}
}
that throws an exception on AssertConfigurationIsValid() and is failing here in the AtlamHttpClient:
public static List<ContentNegotiator> extensionMappings = new List<ContentNegotiator>()
{
new ContentNegotiator("xml", "application/xml", new XmlMediaTypeFormatter()),
new ContentNegotiator("json", "application/json", new JsonMediaTypeFormatter()),
new ContentNegotiator("pack", "application/x-msgpack", new MessagePackMediaTypeFormatter())
};
which in turn calls:
public MessagePackMediaTypeFormatter()
{
MediaTypeHeaderValue val = MediaTypeHeaderValue.Parse(mime);
SupportedMediaTypes.Add(val);
}
and fails with an ArrayTypeMismatchException. Can't figure out why the first project works fine and the second one is failing. Any help would be greatly appreciated.