Windsor resolve issue - ASP.NET Core Web API .Net version 6 cannot register my .Net framework 4.8 C# Library assembly

369 Views Asked by At

I am trying to get my component to be resolved in my Web API project. I am using this code snippet for registering which works fine in my UnitTest project.

Program.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:

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:

<?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. 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.

Can anyone shed some light on what I am missing, please?

1

There are 1 best solutions below

1
OwnageIsMagic On

Use .NET Standard TFM instead of NET Framework. This way the assembly would be compatible between runtimes.

I was under the impression that .net core was backward compatible

The main idea behind Net Core is to allow moving forward and breaking back-compat. 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.


UPD:

Starting form Net Core 2.0 can load NetFx assemblies (but not the other way). Make sure you correctly typed AssemblyQualifiedName of type (including PublicKeyToken and exact assembly version (it's not the same as file version)). Assembly should be placed near your application assembly (verify with AppContext.BaseDirectory from what directory your exe is running). Winsdor is using Type.GetType to find your type, you can debug it.