Unit tests failing only on the build server - c#

It throws an exception that is something like this:
Initialization method MyAssemblyA.Initialize threw exception.
Spring.Objects.Factory.ObjectCreationException: Spring.Objects.Factory.ObjectCreationException:
Error thrown by a dependency of object 'messageSource' defined in 'assembly
[MyOtherAssembly.Test, Version=1.1.1016.1, Culture=neutral, PublicKeyToken=null],
resource [MyOtherAssembly.context.xml]
line 256' : Initialization of object failed : Could not load file or assembly 'MyAssemblyB'
or one of its dependencies. The system cannot find the file specified.
I don't know exactly why, but a lot of the unit tests are failing only on the build server and the exception that is thrown is something similar to what I wrote above.
In my context.xml I have something like this:
<object name="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="resourceManagers">
<list>
<ref object="resMgrCoreServiceErrors"/>
<ref object="resMgrPersonnelErrors"/>
</list>
</property>
</object>
<object name="resMgrCoreServiceErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssembly.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssembly"/>
</object>
<object name="resMgrPersonnelErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssemblyB.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssemblyB"/>
</object>
where ErrorRes is a resource file (.resx).
Please help, any suggestions are welcomed !

are all of the dependencies of MyAssemblyB either installed in the gac or in the bin? has to be something in that vein.

Related

NHibernate throws an exception 'Data Source cannot be empty'?

I'm a newbie to NHibernate and trying to get my first app working with NHibernate + SQLite - In memory DB.
so far, I've done the following,
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<reflection-optimizer use="true"/>
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">"Data Source=:memory:;Version=3;New=True;"</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.release_mode">on_close</property>
<property name="query.substitutions">true=1;false=0</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Hibernate.cs
public NHibernate.ISessionFactory Hibernate()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "hibernate.cfg.xml"));
cfg.AddAssembly(System.Reflection.Assembly.GetExecutingAssembly());
var sessionFactory = cfg.BuildSessionFactory();
return sessionFactory;
}
Now when I call Hibernate() function, the following line throws an exception,
var sessionFactory = cfg.BuildSessionFactory();
Exception :
System.ArgumentException: 'Data Source cannot be empty. Use :memory: to open an in-memory database'
I've been trying to fix this for quite some time now, I have tried with different connection strings, but I've had no luck. Any suggestions/guidance would be much appreciated.
Many thanks.
I doubt there should be double quotes around the value of the connection string property in the configuration file.

SpringNet load configuration file from environment variable?

I use C# and Spring Net 1.3.2 in console app.
I got :
an app.cfg
a spring-context.xml
a environnement.xml file wich contains specific variables values according to the where the app is running : a folder for production, one for qa, and one for test.
What I want to achieve :
in my shell (windows), before launching the app with foo.bat, I do :
set environment="qa"
When Spring loads the context, it picks the value contained in the environment var (say qa), and loads the correct file : thus replacing : configuration/{environment}/vars.xml
by configuration/qa/vars.xml.
In my my spring-context.xml file, I got objects like this : value = ${connectionString.DB1}" where the value is defined inside each vars.xml file (remember, one for prod, one for qa...).
For now, I am not able to replace the ${environment} variable. So I did it programmatically by getting the value of ${environment} with System.Environment.GetEnvironmentVariable("environnement"); and using Path.Combine, load the two contexts myself :
reader.LoadObjectDefinitions(envPath);
reader.LoadObjectDefinitions("configuration/common/springContext.xml");
BUT :
I would like to make it by configuration.
I've been playing with (with no luck) :
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
</list>
</property>
</object>
<object name="appConfigPropertyHolder"
type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="EnvironmentVariableMode" value="Override"/>
</object>
Any ideas ?
Ok, after much research, it works!
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
<object type="Spring.Objects.Factory.Config.PropertyFileVariableSource, Spring.Core">
<property name="Location" value="${root.config}/envars.properties" />
<property name="IgnoreMissingResources" value="false"/>
</object>
</list>
</property>
</object>
path to property file depends upon the environment variable.
Variables are replaced by the values obtained from the properties file.
I deploy one package + folder with 4 environment properties files
And I set my env var accordingly.
No need to mess with app.config or multiple Spring configuration files.

How can I get my Spring.net Webservice working?

I am trying to setup a Spring.net web-service but keep getting an error message that I cannot figure out.
Error:
System.NotSupportedException: Target 'target' of type 'Spring.Objects.Factory.Support.RootWebObjectDefinition' does not support methods of 'StudentRegistration.Services.IBoundaryService'.
at Spring.Util.AssertUtils.Understands(Object target, String targetName, Type requiredType)
at HelloWorldExporter.GetAllBounds()
Code:
public interface IBoundaryService {
XmlDocument GetAllBounds();
}
public class BoundaryService :IBoundaryService
{
public virtual IBoundaryDao BoundaryDao { get; set; }
public virtual XmlDocument GetAllBounds()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<test>ok</test>");
return xmlDoc;
}
}
Configuration:
<object name="BoundaryService" type="StudentRegistration.Services.BoundaryService, StudentRegistration"
abstract="true">
</object>
<object id="BoundaryExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="BoundaryService"/>
<property name="Namespace" value="http://fake/services"/>
<property name="Description" value="something"/>
<property name="MemberAttributes">
<dictionary>
<entry key="GetAllBounds">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="something."/>
<property name="MessageName" value="GetAllBounds"/>
</object>
</entry>
</dictionary>
</property>
</object>
What should I try to clear this up?
The Spring.NET reference is wrong on the xml declaration (i had the same issue a few days ago), or should i say its not crystal clear.
<object name="BoundaryService"
type="StudentRegistration.Services.BoundaryService, StudentRegistration"
abstract="true" />
the above declaration applies when you have an actual .asmx service
WHen you have a PONO which you export as a WebService using Spring.Web.Services.WebServiceExporter the object that will be exported must be declared as:
<object id="BoundaryService"
type="StudentRegistration.Services.BoundaryService, StudentRegistration"
/>
the target property of the WebServiceExporter applies to the id of a declared object, the abstract part is not required as Spring.NET takes the role generating the webservice.
Note that your exposed service name (with your current cfg) will be (..)/BoundaryExporter.asmx
Edit:
The config statement for standard .asmx web services using the name, type attributes seems to be broken, at least for spring version 1.3.0.20349

Configuring NHibernate via Web.config in ASP.NET 4.0

So my unit tests are green, time to integrate this shiny new NHibernate-driven DAL in to my web app! I don't really want to maintain two configuration files so I've migrated hibernate.cfg.xml in to my Web.config file (i.e. I copypasta'd the contents of hibernate.cfg.xml in to my Web.config). Here is the relevant bits from my Web.config:
<configSections>
<section name="combres" type="Combres.ConfigSectionSetting, Combres, Version=2.0.0.0, Culture=neutral, PublicKeyToken=49212d24adfbe4b4"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=(local)\SQLExpress;Initial Catalog=MyProject;Integrated Security=True</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<listener class="MyProject.Sql.Listeners.SaveEventListener, MyProject" type="save"/>
<listener class="MyProject.Sql.Listeners.UpdateEventListener, MyProject" type="update"/>
</session-factory>
</nhibernate>
In Global.asax, on Application_Start, I try to initialize my configuration:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
SessionProvider.Initialize();
}
All this really does is call new Configuration().Configure().AddAssembly("MyProject"); in accordance with the configuration code above.
Interesting result: When I first hit the page, an exception is thrown:
[FileNotFoundException: Could not find file 'D:\Build\MyProject\Source\MyProject.Web\bin\hibernate.cfg.xml'.]
Well, I put the configuration in Web.config, shouldn't it be lookign there? Do I need to indicate "hey, NHibernate, pay attention -- the config data is in Web.config, dummy!" anywhere?
When I then hit F5, the page comes up. Hurray! Now I try to do something with data access and I get this exception:
[ProxyFactoryFactoryNotConfiguredException: The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>]
Huh, that's kinda weird too -- this worked just fine in test with configuration in hibernate.cfg.xml...and I am specifying this property in my Web.config...I wonder what could possibly be up?
So, anyone have any ideas? Any help in solving this mystery would be super!
*Update: I found the issue. It looks like I wasn't using the correct type in my configs section! D'oh. I have a complete write up on my blog.
Try calling the .Configure() method at the end:
new Configuration().AddAssembly("MyProject").Configure();
Or if you prefer put it into the web.config:
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="">
...
<mapping assembly="MyProject" />
</session-factory>
</nhibernate>
and then:
new Configuration().Configure();
Also make sure that the NHibernate.ByteCode.Castle.dll assembly is referenced in your web project.
It turns out that I was using the wrong type in the configuration section. You need to use NHibernate's section handler, not the generic .NET one. The behavior I was seeing was because it was all loaded in a singleton. On first visit, the configuration would fail. On subsequent visits it would just throw weird errors because the configuration failed originally!
There is one other caveat -- I have a complete writeup on my blog.

How to specify an object property type in Spring.NET

I am trying to create an object in Spring where one of its propertys is of type object. Now if I do the following:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4">
</object>
Then the property my_property will be a string object. Is there a way do something like:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4" type="System.Double, System">
</object>
I know this should probably be done by generics but we can't really add this in now as the person who wrote it didn't think of this at the time.
You should be able to do this using the 'expression' tag. e.g.
<property name="my_property" expression="double.Parse('4')" />
See the Spring.NET documentation here

Categories

Resources