PDA

View Full Version : Using Spring to write COM objects / Assemby search path


dziegel
04-26-2007, 08:37 AM
Hello,

I ran into the following two problems when using Spring to write COM components:

1) The issue discussed here (JIRA-533): http://forum.springframework.net/showthread.php?t=2531

2) I do not want to use the GAC for my application. So the Spring DLLs are located in the same directory as my COM component (NOT the directory of the application(s) using my component).
When I use the XML Spring configuration, Spring throws an exception that it cannot load the Spring.Core.dll. This happens because the Config file schema is an embedded resource in the Spring.Core.dll and Spring tries to load the assembly (IResource abstraction) although the Assembly is already in memory.
This can be "fixed" by calling "Spring.Util.SystemUtils.RegisterLoadedAssemblyReso lver()", but I think this is not a very clean solution. Either Spring should detect that the assembly is already loaded or Spring should have a configurable search path for assemblys (at least .NETs Assembly.Load() is too limited). IMHO, RegisterLoadedAssemblyResolver() was only intended to be a workaround to Microsofts' problems with deserialization (http://forum.springframework.net/showthread.php?t=1920).

What is your opinion on this problem?

If you think this is an issue I'll create a JIRA entry for this.

Greetings,
Dirk

Erich Eichinger
04-26-2007, 09:47 AM
Hi Dirk,

Thanks for your research so far. Can you provide us with sample code to reproduce the problem on our machines?

Another suggestion: Try to use fully qualified typenames in your object definitions, e.g.

type="MyNS.MyType, MyAssembly, Version=, Culture=, PublicKeyToken="

and see if this helps

cheers,
Erich

dziegel
04-26-2007, 10:40 AM
Hello Erich,

this should be reproducable with the same project I created for JIRA-533. You must simply remove the Spring DLLs from the GAC on your machine to see this.

To the problem again: It's not me loading an Assembly, it's Spring itself that tries to load Spring.Core.dll to get the embedded resource "spring-objects.xsd". And Spring uses a fully qualified type name to do this. I debugged it already, and I could see that Spring internally tries to load the DLL in the Spring.Core.IO.AssemblyResource constructor using .NETs Assembly.Load / Assembly.LoadWithPartialName methods. The search path of these methods is (by default, without RegisterLoadedAssemblyResolver() ) limited to Application path and GAC. This behavior is hardwired in Spring and I cannot tell Spring to load the DLL in another path, except by the RegisterLoadedAssemblyResolver() workaround.

Dirk

Erich Eichinger
04-26-2007, 11:58 AM
Hi,

I just tried your sample project and was able to run it gacless (nice word, isn't it ;-)) without problems.

-Erich

dziegel
04-26-2007, 12:17 PM
Hello Erich,

Hmm... can't try it here at the moment because the project is at home (and I am at work), but I also observed that you may have to start the app "free running", that means not in Visual Studio. Have you also checked what VS says where Spring loads the assemblys from? Maybe the project version I sent earlier copies them to the host executable dir (I will send a corrected version if this is the case).

Dirk

Erich Eichinger
04-26-2007, 12:32 PM
Hi,

I executed the SpringConfigImportHost.exe from within the directory .\SpringConfigImportHost\Debug\

the COM assembly + Spring are loaded from .\SpringConfigImportCOMObject\bin\Debug\

do you have net 1.1 sp1 installed? I tested with net 1.1 sp1 on w3k

Btw: obviously assemblies referenced from a COM component are searched in this order:

1) GAC
2) Host-Process app directory
3) COM assembly's directory


-Erich

dziegel
04-26-2007, 01:16 PM
Hello Erich,

I managed to get the project work here. This is what VS tells me:


'SpringConfigImportHost.exe': 'W:\SpringConfigImport\SpringConfigImportHost\Debu g\SpringConfigImportHost.exe' geladen, Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\ntdll.dll' geladen, Keine Symbole geladen.

[many MS system DLLs loaded here, deleted for brevity]

'SpringConfigImportHost.exe': 'C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\msco rsn.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost': 'w:\SpringConfigImport\SpringConfigImportHost\Debu g\SpringConfigImportHost.exe' geladen, Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\msco rjit.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\clbcatq.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\comres.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\version.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\sxs.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'W:\SpringConfigImport\SpringConfigImportCOMObject \bin\Debug\SpringConfigImportCOMObject.dll' geladen, Die Symboldatei enthält keine systemeigenen Symbole.
'SpringConfigImportHost.exe': 'w:\springconfigimport\springconfigimportcomobject \bin\debug\springconfigimportcomobject.dll' geladen, Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\assembly\GAC\System\1.0.5000.0__b77a5c 561934e089\System.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\assembly\NativeImages1_v1.1.4322\Syste m\1.0.5000.0__b77a5c561934e089_1ee332bd\System.dll ' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c 561934e089\system.dll' geladen, keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\system32\rsaenh.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'c:\windows\assembly\gac\mscorlib.resources\1.0.50 00.0_de_b77a5c561934e089\mscorlib.resources.dll' geladen, keine Symbole geladen.
'SpringConfigImportHost.exe': 'w:\springconfigimport\springconfigimportcomobject \bin\debug\spring.core.dll' geladen, keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\assembly\GAC\System.Xml\1.0.5000.0__b7 7a5c561934e089\System.Xml.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'C:\WINDOWS\assembly\NativeImages1_v1.1.4322\Syste m.Xml\1.0.5000.0__b77a5c561934e089_e34c221b\System .Xml.dll' geladen, Keine Symbole geladen.
'SpringConfigImportHost.exe': 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b7 7a5c561934e089\system.xml.dll' geladen, keine Symbole geladen.
Constr
w:\springconfigimport\springconfigimportcomobject\ bin\debug\
'SpringConfigImportHost.exe': 'w:\springconfigimport\springconfigimportcomobject \bin\debug\common.logging.dll' geladen, keine Symbole geladen.
'SpringConfigImportHost.exe': 'Spring.DynamicReflection' geladen, keine Symbole geladen.
'SpringConfigImportHost.exe': 'Spring.DynamicReflection' geladen, keine Symbole geladen.
Eine nicht behandelte Ausnahme des Typs 'System.IO.FileNotFoundException' ist in spring.core.dll aufgetreten.

Zusätzliche Informationen: Unable to load assembly [Spring.Core, Version=1.1.0.1, Culture=neutral, PublicKeyToken=65e474d141e25e07]


Exception location:

spring.core.dll!Spring.Core.IO.AssemblyResource.As semblyResource(string resourceName = "assembly://Spring.Core, Version=1.1.0.1, Culture=neutral, PublicKeyToken=65e474d141e25e07/Spring.Objects.Factory.Xml/spring-objects.xsd") + 0x108 Bytes

Spring.DynamicReflection!Spring.DynamicReflection. Ctor_AssemblyResource_2f8815a0b9fa44f09a2b90af5519 0aa4.Invoke(System.Object[] args = {Length=1}) + 0x39 Bytes

spring.core.dll!Spring.Core.IO.ConfigurableResourc eLoader.GetResource(string resourceName = "assembly://Spring.Core, Version=1.1.0.1, Culture=neutral, PublicKeyToken=65e474d141e25e07/Spring.Objects.Factory.Xml/spring-objects.xsd") + 0xcd Bytes

spring.core.dll!Spring.Objects.Factory.Xml.XmlPars erRegistry.RegisterParser(Spring.Objects.Factory.X ml.IXmlObjectDefinitionParser parser = {Spring.Objects.Factory.Xml.DefaultXmlObjectDefini tionParser}, string namespaceUri = "http://www.springframework.net", string schemaLocation = "assembly://Spring.Core, Version=1.1.0.1, Culture=neutral, PublicKeyToken=65e474d141e25e07/Spring.Objects.Factory.Xml/spring-objects.xsd") + 0x181 Bytes

[...]

spring.core.dll!Spring.Context.Support.XmlApplicat ionContext.XmlApplicationContext(string[] configurationLocations = {Length=1}) + 0x1b Bytes

springconfigimportcomobject.dll!SpringConfigImport COMObject.SpringConfigImportCOMObject.SpringConfig ImportCOMObject() Zeile 37 + 0x4e Bytes C#


As you can see, the Spring.Core.dll is initially loaded from the right place, but at the point where Spring tries to load it's schema, it cannot find the DLL any more.

System WinXP Prof SP1, .NET 1.1 SP1. I've tried this now on 2 different machines, both WinXP SP1 + .NET 1.1 SP1 with the same result.

Dirk

Erich Eichinger
04-26-2007, 01:34 PM
Strange - it's working on my machine at home as well. Did you check your fusion log for any reasony why Spring.Core refuses to load?

-Erich

dziegel
04-26-2007, 02:41 PM
Hello,

this is really strange... The fusion log (which I didn't know before, thanks for pointing me to this) didn't tell me something new (assembly was searched in Host app path). What I do not understand is that I don't see any successful binding of Spring.Core in the fusion log, only the failure.

But this problem happens only when I run my app in DevStudio (VS 2003), if I start it directly everything works fine. So let's file this for the moment under "some VS problem" - I'll continue to try to figure out what this is. I guess this has something to do with the fact that VS has already loaded the DLL because it is referenced by the project.

Enough of wasting of your time for the moment.

Thanks for your hints,
Dirk