[英]Windsor resolve issue - ASP.NET Core Web API .Net version 6 cannot register my .Net framework 4.8 C# Library assembly
I am trying to get my component to be resolved in my Web API project.我试图让我的组件在我的 Web API 项目中得到解决。 I am using this code snippet for registering which works fine in my UnitTest project.
我正在使用此代码片段进行注册,这在我的 UnitTest 项目中运行良好。
Program.cs程序.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
IWindsorContainer container = new WindsorContainer(new XmlInterpreter("Windsor.config"));
container.Resolve<IDataProvider>();
But in my.Net Core Web API project I get this error:但是在 my.Net Core Web API 项目中我得到了这个错误:
Castle.MicroKernel.SubSystems.Conversion.ConverterException
HResult=0x80131500
Message=Could not convert string 'MyProject.DataAccess.DataProviders.PDataProvider, MyProject.DataAccess, Version=1.0.0.0, Culture=neutral' to a type. Assembly was not found. Make sure it was deployed and the name was not mistyped.
Source=Castle.Windsor
StackTrace:
at Castle.MicroKernel.SubSystems.Conversion.TypeNameConverter.GetType(String name)
at Castle.MicroKernel.SubSystems.Conversion.TypeNameConverter.PerformConversion(String value, Type targetType)
at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion(String value, Type targetType)
at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion[TTarget](String value)
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter)
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store)
at Program.<Main>$(String[] args) in C:\source\repos\F2\MyProject.F2\Program.cs:line 8
My Windsor.config file:我的 Windsor.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<castle>
<components>
<component id="DataProvider"
service="MyProject.Interfaces.DataProviders.IDataProvider, MyProject.Interfaces"
type="MyProject.DataAccess.DataProviders.PDataProvider, MyProject.DataAccess, Version=1.0.0.0, Culture=neutral"></component>
</components>
</castle>
My 'MyProject.DataAccess.dll' is in the '/bin' folder for both debug and release, which I am copying manually.我的“MyProject.DataAccess.dll”位于用于调试和发布的“/bin”文件夹中,我正在手动复制它。 Either the 'MyProject.DataAccess.dll' should be copied elsewhere where the Web API app can 'see' or locate it or the version of 'MyProject.DataAccess.dll' (.Net framework 4.8) is a problem.
应将“MyProject.DataAccess.dll”复制到 Web API 应用程序可以“查看”或找到它的其他位置,或者“MyProject.DataAccess.dll”(.Net framework 4.8)的版本有问题。
Can anyone shed some light on what I am missing, please?任何人都可以阐明我所缺少的东西吗?
Use .NET Standard TFM instead of.NET Framework.使用.NET 标准TFM 而不是 .NET Framework。 This way the assembly would be compatible between runtimes.
这样程序集将在运行时之间兼容。
I was under the impression that .net core was backward compatible
我的印象是 .net 内核向后兼容
The main idea behind Net Core is to allow moving forward and breaking back-compat. Net Core 背后的主要思想是允许向前移动和向后兼容。 They (Core team) somewhat trying to be source-level compatible to easier mitigation from.NETFx, but it's not a goal in the long term run.
他们(核心团队)在某种程度上试图实现源代码级兼容,以便更容易地从 .NETFx 中缓解,但这不是长期目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.