Windsor Conflict Conflicts

Let's say I work in a namespace called, for example, Org.Company , and that this namespace contains MyClass . I also import nuget with a namespace named Company with a class called OtherClass .

So, when I work inside my Org.Company namespace, I cannot do the following:

Company.OtherClass obj;

because the compiler assumes that I actually mean:

Org.Company.Otherclass obj

which does not exist.

So, as far as I know, instead of using the full name, I really MUST import another namespace as such using Company;

The problem is that I need to reference this OtherClass from the XML file (Castle Windsor configuration file), and the full name of Company.OtherClass does not work. Is there any way around this? Changing namespace names is not a viable option.

EDIT: This is what I have in the Castle Windsor xml file

 <using assembly="MyProj, Version=1.0.0.0, Culture=neutral" /> ... <component service="Company.IOtherClass" type="Company.OtherClass" /> 

I get the following error:

{"Could not convert string 'Company.OtherClass' to a type. Make sure assembly containing the type has been loaded into the process, or consider specifying assembly qualified name of the type."}

Perhaps because instead he searches inside the Org.Company defined in the MyProj assembly.

I suppose this can be fixed if there is a way to add another <using /> statement that references the Nuget package ... Is there a way to do this?

+4
source share
3 answers

As far as I understand, your problem is with the XML link? Right?

Since Castle.Windsor suggests "consider specifying a qualified assembly name of the type." What does it mean? This means that instead of:

 <component service="Company.IOtherClass" type="Company.OtherClass" /> 

You must specify the class names using the assembly from which they come:

 <component service="Company.IOtherClass, OtherClassAssembly" type="Company.OtherClass, OtherClassAssembly" /> 

or even the full assembly name:

 <component service="Company.IOtherClass, OtherClassAssembly, Version=..., Culture=..., PublicKeyToken=..." type="Company.OtherClass, OtherClassAssembly, Version=..., Culture=..., PublicKeyToken=..." /> 

NOTE : replace OtherClassAssembly with the actual assembly name and DO NOT add the .dll extension here NOTE : see http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx for more details, such as handle nested classes

To use OtherClass code in code, you can use global

 global::Company.OtherClass 

you can also use with:

 using Company; 

or just import one class:

 using ClassFromOtherCompany = Company.OtherClass; 
+5
source

You can use a namespace alias, something like this MSDN example:

 using Co = Company.Proj.Nested; 
0
source

Well, judging by the description of the problem and the error message you receive, it seems your suspicion is true.

The assembly from the Nuget package was not loaded into the AppDomain by the time Windsor launches its installers, so it does not know where to get Company.OtherClass .

You can also do what the error message suggests and use the name of the assembly type, or preload the assembly with the <using /> .

0
source

Source: https://habr.com/ru/post/1480909/


All Articles