0
votes

I'm trying to setup Web API project that uses OWIN and NInject middleware. I've installed Ninject.Web.WebApi.OwinHost nuget package and created the following startup class:

public class Startup
{
    public void Configuration(IAppBuilder appBuilder)
    {
        var httpConfig = new HttpConfiguration();
        WebApiConfig.Register(httpConfig);
        appBuilder.UseNinjectMiddleware(CreateKernel);
        appBuilder.UseNinjectWebApi(httpConfig);
    }

    private StandardKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        return kernel;
    }
}

This code throws the following exception during initialization when creating StadardKernel:

Type 'SomeType' in assembly 'SomeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

I'm very confused why this error is returned as I haven't registered any bindings yet. Type SomeType is in third party assembly I'm using and cannot be modified.

1
I'll try to reproduce your issue. Can you provide the assembly or type? - Stefan Ossendorf

1 Answers

0
votes

What are you sending to your api? As the exception states, you are trying to serialize/deserialize a type which is not marked as serializable. DataContractSerializer or XmlSerializer need it.

See the remarks part: MSDN SerializableAttribute