我正在尝试将我的代码从运行在.NET Framework 4.6.1上的Webjobs项目迁移到新的.NET Core 2.0控制台项目。我在这里遇到错误:
class Program
{
// Here I'm getting IKernel is obsolete. Use IKernelConfiguration and IReadOnlyKernel message.
// Also a message that reads: StandardKerynel is obsolete. Use StandardKernelConfiguration and StandardReadOnlyKernel
static readonly IKernel Kernel = new StandardKernel();
static JobHostConfiguration config;
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("AzureWebJobsDashboard", "connection");
Environment.SetEnvironmentVariable("AzureWebJobsStorage", "storage connection");
BootStrapIoc();
config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
host.RunAndBlock();
}
private static void BootStrapIoc()
{
// Also getting an error here that reads: Argument 1: Cannot convert System.Reflection.Assembly to System.Collections.Generic.IEnumerable<Ninject.Modules.NinjectModule>
Kernel.Load(Assembly.GetExecutingAssembly());
config = new JobHostConfiguration
{
JobActivator = new BrmJobActivator(Kernel)
};
}
}
我的BrmJobActivator代码中也出现错误:
public class BrmJobActivator : IJobActivator
{
private readonly IKernel _container;
public BrmJobActivator(IKernel container)
{
_container = container;
}
public T CreateInstance<T>()
{
return _container.Get<T>();
}
}
答案 0 :(得分:1)
此处出现错误:参数1:无法将System.Reflection.Assembly转换为System.Collections.Generic.IEnumerable
Ninject的最新预发布版本有一些变化。请安装最新的稳定3.2.2版本。
我测试了你的代码。在将Ninject版本更新为3.2.2之后,代码运行良好。
答案 1 :(得分:0)
Ninject 3.3.0于2017年9月26日发布,现在定位于 .NET Standard 2.0 ,因此也可以在.NET Core 2.0上运行。更新到3.3.0将修复警告。