PDA

View Full Version : Weird Problem in Spring.NET property setter injection


hpcd
02-17-2007, 06:29 AM
I am working on a Win Forms .NET 2.0 app and I'm using Spring to wire up the various classes.

Things were working well up to earlier today, but then I started getting the famous Context error. In an attempt to trace things, I'm stripped out almost all of the XML, except for the one for the main form that will launch in Program.cs. Here are some of the things I've found:

a) If the class has constructor and I try to inject, no problems..it works
b) As soon as I add a string Propertty to inject some static text, I get a error thrown in the class. The property isn't doing anything in the class-not even setting a text box. As soon as I comment out the property from the XML, things work.

Any ideas? I'm using Spring.NEt 1.0.2.

Here is a sample:

I added Form1 to the project:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyAssembly
{
public partial class Form1 : Form
{
public string MyText
{
set
{
// do nothing.
}
}

public Form1()
{
InitializeComponent();
}
}
}


This form doesn't have any controls (just added Form1 and added the property).


I'm using:


IApplicationContext appctx= new XmlApplicationContext(
"file://views.spring.cfg.xml"
);
Form mainForm = appctx.GetObject("appShellForm");

Application.Run(mainForm);


Using XmlApplicationContext, because the error messages are more detailed than if you use ContextRegistery and app.config handlers.


The XML is (views.spring.cfg.xml):

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



<object id="appShellForm" type="MyAssembly.Form1, MyAssembly">
<!--<property name="MyText" value="Set Me" />-->
</object>
</objects>

When I uncomment the property setter, I get the following error:

Error creating object with name 'appShellForm' defined in 'file [C:\todelete\MyAssembly\bin\Debug\views.spring.cfg. xml]' : Initialization of object failed : Could not load file or assembly 'antlr.runtime, Version=2.7.5.22, Culture=neutral, PublicKeyToken=65e474d141e25e07' or one of its dependencies. The system cannot find the file specified.

This is stumping me. The only thing left, is for me to create a brand new project and start adding files one by one. I'll probably try that and see. Thanks in advance.

Bruno Baia
02-17-2007, 08:26 AM
Hi,

Are you sure the right antlr.runtime.dll version in the bin directory ?

btw, I recommend you to update to the 1.1 P3 version.


Hope this helps,
Bruno

Erich Eichinger
02-17-2007, 12:19 PM
Hi,

Take care, that you update your antlr.runtime.dll as well. The P3's version is 2.7.6.2 - it took me a lot of time in one of my own projects as I forgot to not only update Spring.* assemblies but also antlr :(

cheers,
Erich

hpcd
02-17-2007, 03:51 PM
Thanks, both, for your suggestions. I will check.

I'm not sure of the policy on using latest versions in production. Would you guys recommend upgrading and using 1.1 P3 for use in a production environment. Anyone already using it in production? Thanks.

Erich Eichinger
02-17-2007, 08:14 PM
Hi,

I would definitely recommend upgrading. I would even suggest to always upgrade to the latest nightly version because we are constantly fixing bugs and improving performance. The API has changed in some cases from 1.0.2 to 1.1P3 and it might require a bit of time to upgrade but it's certainly worth the effort. As we are approaching RC1, I expect the API to be quite stable now.

I've got all the major stuff (Web-DI, WebServices, AOP, Transactions, NHibernate+OpenSessionInView) in production in ~10 mid/high-loaded Websites here.

hope this helps,
Erich

hpcd
02-19-2007, 04:20 PM
Thanks for the info. Your suggestions were right on the money! It was a missing antlr.runtime.dll. It was there before because the application worked around just after noon last Friday. I think VSS must be playing tricks or something and when I got latest version something must have went wrong:mrgreen: