首页 > 解决方案 > 类型未标记为可序列化

问题描述

我在.net 4.6.1 web api项目中使用这个命令postbuild。

$(NSwagExe) aspnetcore2swagger "/assembly:$(TargetPath)" "/output:$(OutputPath)swagger.json"

然而它在两个地方失败了,第一个是,

1>System.IO.FileNotFoundException:未找到配置文件“appsettings.json”且不是可选的。物理路径是 'C:\Users\XXXX\source\Workspaces\Information Systems\SOLUTION\SOLUTION.Api\bin\x64\Debug\

appsettings.json 文件与 Startup.cs 位于同一目录中。这就是我得到它的方式

  public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json")

现在继续前进,只是为了让它工作,如果我硬编码路径它工作但我得到这个错误,

5>System.Runtime.Serialization.SerializationException:在程序集“StructureMap,Version=4.5.0.0,Culture=neutral,PublicKeyToken=null”中键入“StructureMap.StructureMapConfigurationException”未标记为可序列化。

这是我在启动时使用此结构图的地方之一,

   Start.LogicContainer.Configure(x => x.For<DBContext>().Use<DBContext>()
                .Ctor<string>("nameOrConnectionString").Is(Configuration.GetConnectionString("DefaultConnection")));

我想要的只是在每次构建时生成 swagger.json 文件。

标签: c#asp.net-web-api.net-4.6.1nswag

解决方案


推荐阅读