PDA

View Full Version : Spring.Core 1.1 P3 and Mono 1.2.3 on windows


raj420
02-08-2007, 12:42 PM
Hi,

Im new to .NET/C#, Spring.NET and Mono as moved over from Java camp where I used Spring happily.

Using Spring.Net successfully on .NET framework but getting following exception on under Mono on windows.


Unhandled Exception: System.Configuration.ConfigurationErrorsException: Error instantiating context 'spring.root'. () () ---> Spring.Objects.FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(String, Boolean, String[])] : 'Exception ha
s been thrown by the target of an invocation.' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
at Mono.Xml.Schema.XmlSchemaValidatingReader.get_Pref ix () [0x00000]
at System.Xml.XmlDocument.ReadAttributeNode (System.Xml.XmlReader reader) [0x00000]
at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000]
at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000]
at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) [0x00000]
at Spring.Objects.Factory.Xml.XmlObjectDefinitionRead er.LoadObjectDefinitions (IResource resource) [0x00000]
at Spring.Context.Support.AbstractXmlApplicationConte xt.LoadObjectDefinitions (Spring.Objects.Factory.Xml.XmlObjectDefinitionRea der objectDefinitionReader) [0x00000]
at Spring.Context.Support.AbstractXmlApplicationConte xt.RefreshObjectFactory () [0x00000]
at Spring.Context.Support.AbstractApplicationContext. Refresh () [0x00000]
at Spring.Context.Support.XmlApplicationContext..ctor (System.String name, Boolean caseSensitive, IApplicationContext parentContext, System.String[] configurationLocations) [0x00000]
at Spring.Context.Support.XmlApplicationContext..ctor (System.String name, Boolean caseSensitive, System.String[] configurationLocations) [0x00000]
at <0x00000> <unknown method>
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[])
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] --- End of inner exception stack trace ---

at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000]
at Spring.Objects.ObjectUtils.InstantiateType (System.Reflection.ConstructorInfo constructor, System.Object[] arguments) [0x00000] --- End of inner exception stack trace ---

at Spring.Objects.ObjectUtils.InstantiateType (System.Reflection.ConstructorInfo constructor, System.Object[] arguments) [0x00000]
at Spring.Context.Support.ContextHandler+RootContextI nstantiator.InvokeContextConstructor (System.Reflection.ConstructorInfo ctor) [0x00000]
at Spring.Context.Support.ContextHandler+ContextInsta ntiator.InstantiateContext () [0x00000] --- End of inner exception stack trace ---

at Spring.Context.Support.ContextHandler+ContextInsta ntiator.InstantiateContext () [0x00000]
at Spring.Context.Support.ContextHandler.InstantiateC ontext (IApplicationContext parentContext, System.Object configContext, System.String contextName, System.Type contextType, Boolean caseSensitive, System.String[] resources) [0x00000]
at Spring.Context.Support.ContextHandler.Create (System.Object parent, System.Object configContext, System.Xml.XmlNode section) [0x00000]


Worked through previous threads on similar issue but no luck. Below is snippet of the objects XML file I am using. Accessing through app.config with resource URI to seperate file .I've tried removing references to the schema etc to see if that solves the issue as seems to be validation issue of sorts.


<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">

<description>Spring managed objects</description>

<!--Injector main class-->
<object id="Injector" type="Test.Integration.Injector.Injector">
<!-- Frequency to poll the IMAP mailbox-->
<property name="pollingInterval" value="1000" />
</object>

<!-- IMAP Agent-->
<object id="ImapClient" type="Test.Integration.Injector.Imap.ImapClient">
<!-- Mailbox details and credentials -->
<property name="mailHost" value="localhost" />
<property name="mailHostPort" value="143" />
<property name="mailusername" value="testbox" />
<property name="mailPassword" value="password" />
<!-- Folders where incoming mail is delivered and moved to post injection -->
<property name="incomingFolder" value="Inbox" />
<property name="injectedFolder" value="Injected" />
<!-- Filter for which message to retrieve -->
<property name="messageFilter" value="1:*" />
<!-- references to which header and attachments processor to use -->
<property name="headerProcessor" ref="PassThroughHeaderProcessor" />
<property name="attachmentsProcessor" ref="MissingAttachmentsProcessor" />
</object>

...................



Not sure where to go with this one now.

Any help much appreciated.

Raj

Bruno Baia
02-12-2007, 03:30 PM
Hi,

Sometimes ago, I've tried the MoMA tool (Mono Migration Analyzer) from http://www.mono-project.com/Moma.
See attached html file report generated by MoMa.

The tool submits the report to the mono team, I specified that the main problem was the missing method :
XmlReader CreateValidatingReader(Stream, XmlSchemaSet, ValidationEventHandler)

Maybe we should remove this validation for mono with a conditional compilation symbol.


Bruno

Erich Eichinger
02-12-2007, 04:21 PM
Hi,

Maybe we should remove this validation for mono with a conditional compilation symbol.

Good idea - this would also solve 1 issue for the Compact Framework build.

-Erich

raj420
02-12-2007, 05:39 PM
Hi,

Thanks for the response and the pointers.

Is there anything I could do to get this working for now while a fix is being worked on i.e. remove the validation for mono?

Thanks

Raj

Erich Eichinger
02-12-2007, 08:47 PM
Hi,

At the moment we are working on getting 1.1RC1 out - our time for working on spring is limited and we are forced to set priorities - so our focus is still more on windows/net platform.

Of course we'd love to see a working mono build - if you can find a way to make spring build & run on mono we would be more than happy if you could help and provide us with your feedback and/or patches!

cheers,
Erich

arbfranklin
03-08-2007, 09:18 AM
I'm suffering from a similar issue, really keen to get the basics of Spring.Core working under mono.

I have the following stack trace:


System.Configuration.ConfigurationErrorsException: Error instantiating context 'spring.root'. () () ---> Spring.Objects.FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(String, Boolean, String[])] : 'Exception has been thrown by the target of an invocation.' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: An exception was thrown by the type initializer for Spring.Core.IO.ResourceHandlerRegistry ---> System.NullReferenceException: Object reference not set to an instance of an object
at System.Reflection.Emit.ModuleBuilder..ctor (System.Reflection.Emit.AssemblyBuilder assb, System.String name, System.String fullyqname, Boolean emitSymbolInfo, Boolean transient) [0x00000]
at System.Reflection.Emit.AssemblyBuilder.DefineDynam icModule (System.String name, System.String fileName, Boolean emitSymbolInfo, Boolean transient) [0x00000]
at System.Reflection.Emit.AssemblyBuilder.DefineDynam icModule (System.String name, Boolean emitSymbolInfo) [0x00000]
at Spring.Util.DynamicCodeManager.GetModuleBuilder (System.String assemblyName) [0x00000]
at Spring.Util.DynamicReflection.DynamicReflectionMan ager.CreateTypeBuilder (System.String name) [0x00000]
at Spring.Util.DynamicReflection.DynamicConstructor.C reate (System.Reflection.ConstructorInfo constructor) [0x00000]
at Spring.Core.IO.ResourceHandlerRegistry.GetResource Constructor (System.Type handlerType) [0x00000]
at Spring.Core.IO.ResourceHandlerRegistry..cctor () [0x00000] --- End of inner exception stack trace ---

at <0x00000> <unknown method>
at Spring.Core.IO.ConfigurableResourceLoader.GetResou rce (System.String resourceName) [0x00000]
at Spring.Context.Support.AbstractXmlApplicationConte xt.LoadObjectDefinitions (Spring.Objects.Factory.Xml.XmlObjectDefinitionRea der objectDefinitionReader) [0x00000]
at Spring.Context.Support.AbstractXmlApplicationConte xt.RefreshObjectFactory () [0x00000]
at Spring.Context.Support.AbstractApplicationContext. Refresh () [0x00000]
at Spring.Context.Support.XmlApplicationContext..ctor (System.String name, Boolean caseSensitive, IApplicationContext parentContext, System.String[] configurationLocations) [0x00000]
at Spring.Context.Support.XmlApplicationContext..ctor (System.String name, Boolean caseSensitive, System.String[] configurationLocations) [0x00000]
at <0x00000> <unknown method>
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[])
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] --- End of inner exception stack trace ---


I tried commenting out the settings.Schemas.Add(schemas); line in CreateValidatingReader and it made no difference to my situation. Any advice on where to look next and I'd really like to get this working when the MoMA advisor thinks it's so close to being working.

arbfranklin
03-10-2007, 04:59 AM
I did a simple patch that fixes the issue, at least for my needs. I've put the fix on my blog at:

http://arbfranklin.com/wp/2007/03/10/springnet-11-on-mono/

Erich Eichinger
03-10-2007, 05:30 AM
Hi Andrew,

Cool! Thanks a lot for investigating this. I'll have a look asap to get the mono build working and will integrate your patch.

Please let us know of any further issues.

cheers,
Erich

arbfranklin
03-10-2007, 10:13 PM
I'm not sure whether you could call my patch of the highest quality just that by skipping all the validators I imagine it opens a world of other problems when the user has an incorrect resource xml. That being said, when you develop on Windows and just want to run your tested working copy on linux, it's very handy.

With regards "Patrick's comment on my blog" about using a mono compilation symbol, that would make the behaviour fixed at compile time, and I'd need 2 versions of the dll lying about depending on whether I was running on my .NET Framework or Mono box. This way I can develop on Windows using the XML Schema based validators, and take the same code and dll across to linux, and have it work straight away.

I'm not sure how you want to integrate the final fix, but runtime detection of mono is desirable for myself for reasons mentioned above.

Erich Eichinger
03-10-2007, 10:22 PM
Hi,

if this is the only difference and it works then I can live with runtime detection.

Otherwise we certainly will treat the mono-version the same way as we did with NET1.1 / 2.0 on windows: having a common codebase but explicitely adding support for special features of the target platform. There are a couple of features that would be too hard to implement when using only runtime-detection.

cheers,
Erich

Mark Pollack
04-17-2007, 10:57 PM
Hi,

Thanks for digging into the mono support Andrew. I've updated CVS to do the runtime check. FYI, I introduced the property, MonoRuntime on SystemUtils as I think we'll need this going forward. CVS is very slow at the moment, so the cruisecontrol build is timing out. Hopefully, this will clear itself up soon and you can pick up a new build soon.

Cheers,
Mark

Mark Pollack
04-18-2007, 02:50 PM
Hi,
We should be able to support validating the xml with the schema in mono, so the current changes are just a quick fix. This JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-296) issue will track it.
Mark

skolima
05-27-2007, 12:50 PM
Guys, you are taking the wrong way. Mono strives to be compatible with .Net. You should not introduce hacks into Spring to make it run on Mono - when something does not work like it does on windows, file a bug with mono. The Mono team is more than willing to help, especially considering how many people are using SpringFramework.net.

The problems with initiating context should be solved now in the svn version of mono (I have filled a bugreport http://bugzilla.ximian.com/show_bug.cgi?id=81460 , which got sorted out by Atsushi Enomoto with help from Gert Driesen).

I run my little test today again, with the svn mono and Spring .Net binaries for win32 2.0 Framework, and most things work fine. Things I bumped into but managed to solve:
-> assembly lookup is case sensitive (this depends on filesystem used). Thus Mscorlib does not refer to mscorlib.dll
-> xbuild compiled my project with mcs (1.1 profile) not gmcs (2.0 profile), so spring was unable to find some 2.0 classes. I worked around this by invoking gmcs manually - this is probably a bug in xbuild.
-> AFAIR, msbuild automatically handles App.config files. xbuild does not, so I had to rename the config file to SpringTest.exe.config (my program is SpringTest.exe).

What I did not solve yet are the indexer properties. I should cook a test case and file a bug with mono some time this week.

EDIT: seems that the indexer problem arouse from a mistake in Spring documentation, which states that spring properties should be accessed with <property name="Item['koza']" value="kozica"> . Instead, what works is <property name="['koza']" value="kozica"> (both on MS.Net and mono).

Bruno Baia
06-25-2007, 04:33 PM
Guys, you are taking the wrong way. Mono strives to be compatible with .Net. You should not introduce hacks into Spring to make it run on Mono - when something does not work like it does on windows, file a bug with mono. The Mono team is more than willing to help, especially considering how many people are using SpringFramework.net.

I agree with you about this.

I've recently used the MoMa tools and sent an report to the mono team.
The main pb I think is that we don't have any "Mono expert" in our team.


Bruno