PDA

View Full Version : problem using XmlApplicationContext to getObject


tdu
04-07-2006, 11:48 PM
I have 3 tier structure. Web,Interface and Web Service. I am using SprintNEt WebService proxy creation at Web service layer and use SprintNet clientproxy creation on my Interface tier. So, my web tier doesn't have to know any knowledge of proxy creation. All it did is using xmlApplicationContext to getObject defined in my Interface tier with embbed the xml resource.
Everything works fine on the first run, but fails on the postback or refresh. It complaints about the "Duplicate type name within an assembly". I have to recycle aspnet work process to be able to run the application again.


On my web tier (not a springNet web aware, only has assembly reference)


private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{


XmlApplicationContext ctx = new XmlApplicationContext("assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml");

SpringNetContract.ContactHelper helper=(SpringNetContract.ContactHelper)ctx.GetObj ect("contactHelper");

this.datagrid1.DataSource=helper.GetXOContacts();
this.datagrid1.DataBind();

}


}


The Contact_Dev.xml is on my Interface tier with embeded resource compilation turned on for the xml file

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<!--

<object id="IContactService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services" >
<property name="ServiceUrl" value="http://localhost/SpringNetService/ContactExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IContact, SpringNetContract" />
</object>

<object id="contactHelper" type="SpringNetContract.ContactHelper,SpringNetContract" singleton="false">
<property name="ContactService" ref="IContactService" />

</object>
</objects>

The Interface tier I have a contactHelper.cs
public ContactHelper()
{

}

#region public property

private SpringNetContract.IContact contactService;

//
public IContact ContactService
{
set { contactService = value; }
get {return contactService;}
}
#endregion

#region public method
public xo.Common.BusinessObject.ContactCollection GetXOContacts()
{
return ContactService.GetXOContacts();
}
Everything hooked up. It worked. However, if I refresh the page, I got some error from AbstractObjectFactory.cs from Spring.Objects.Factory.Support on line 598(I am using the 4/7/06 build)

The error message is:
Duplicate type name within an assembly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Duplicate type name within an assembly.

Source Error:


Line 54: XmlApplicationContext ctx = new XmlApplicationContext("assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml");
Line 55:
Line 56: SpringNetContract.ContactHelper helper=(SpringNetContract.ContactHelper)ctx.GetObj ect("contactHelper");
Line 57:
Line 58: this.datagrid1.DataSource=helper.GetXOContacts();


Source File: c:\springnetexample\sample\springnetwebclient\webf orm2.aspx.cs Line: 56

Stack Trace:


[ArgumentException: Duplicate type name within an assembly.]
System.Reflection.Emit.AssemblyBuilderData.CheckTy peNameConflict(String strTypeName, TypeBuilder enclosingType) +312
System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +176
System.Reflection.Emit.TypeBuilder..ctor(String name, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, TypeBuilder enclosingType) +28
System.Reflection.Emit.ModuleBuilder.DefineType(St ring name, TypeAttributes attr, Type parent) +88
Spring.Proxy.CompositionProxyTypeBuilder.CreateTyp eBuilder() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Proxy\CompositionProxyTypeBuilder.cs:198
Spring.Web.Services.SoapHttpClientProxyTypeBuilder .BuildProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:505
Spring.Web.Services.WebServiceClientFactory.Genera teProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:334
Spring.Web.Services.WebServiceClientFactory.GetObj ect() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:263
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObjectForSharedInstance(String name, Object instance) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :596

[ObjectCreationException: Error thrown by a dependency of object 'contactHelper' defined in 'assembly [SpringNetContract, Version=1.0.2288.29063, Culture=neutral, PublicKeyToken=null], resource [SpringNetContract.Config.Contact_Dev.xml]' : IFactoryObject threw exception on object creation.
while resolving 'ContactService' to '' ]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ResolveReference(IConfigurableOb jectDefinition definition, String name, String argumentName, RuntimeObjectReference reference) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1703
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ResolveValueIfNecessary(String name, RootObjectDefinition definition, String argumentName, Object argumentValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1584
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:290
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:394
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:745
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:609
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :242
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1203
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1163
Spring.Context.Support.AbstractApplicationContext. GetObject(String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractApplicationContext.cs:11 22
springTest.WebForm2.Page_Load(Object sender, EventArgs e) in c:\springnetexample\sample\springnetwebclient\webf orm2.aspx.cs:56
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +739




Any help is appreciate.

Thanks

Tony

Bruno Baia
04-09-2006, 01:03 AM
Hi Tony,

the pb is you are creating the context for each request ( new XmlApplicationContext ).
If you don't want to configure objects in the web application and uses directly the WebApplicationContext, u need to save the context created somewhere like the http application state.

Add this property to the page, and use this property when using the context :

public IApplicationContext GetContext
{
get
{
if (HttpContext.Current.Application["SpringContext"] == null)
HttpContext.Current.Application["SpringContext"] = new XmlApplicationContext("assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml");

return (IApplicationContext)HttpContext.Current.Applicati on["SpringContext"];
}
}



Btw, there is a problem in WebServiceClientFactory, because the type name is not unique, i'll change it to make it unique.


-Bruno

tdu
04-10-2006, 03:19 PM
It worked. Can you let me know what build that you made the change to the unique name of clientservicefactory.

Thans so much

Tony

Bruno Baia
04-10-2006, 03:34 PM
Hi,

the latest nightly build (Spring.NET-20060409-2203) contains the modification but you should keep the context into the HttpApplicationState, it's avoid the creation of the web services proxy for each request.


-Bruno

tdu
04-12-2006, 10:26 PM
Thanks. I got that web tier all worked out.
However, When I tried to use Aop to create object and reference to the web service (on my web service tier), I got the same Duplicate type name error.

Here is my Aop config on my service layer:


<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="Log4NetLoggingAroundAdvice" type="Aspects.Logging.Log4NetLoggingAroundAdvice, Aspects">
<property name="Level" value="Debug" />
</object>




<object id="getContact" type="xo.Common.Services.AccountManagement.xoContact, xo.Common.Services.BC"/>

<object id="BC.Contact" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName"><value>getContact</value></property>

<property name="Interfaces" >
<list>
<value>xo.Common.Interfaces.AccountManagement.IContact, xo.Common.Interfaces.BC</value>
</list>
</property>
</object>

<object id="BC.Contact.Aop" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="target" ref="BC.Contact"/>
<property name="interceptorNames">
<list>
<value>Log4NetLoggingAroundAdvice</value>
</list>
</property>
</object>

</objects>



I want to apply the Log4NetLoggingAroundAdvice to my web service.

The error I got is the same one I got before. I am using 4/92006 build. I am not having that problem on my client tier.
Here is the error:

Duplicate type name within an assembly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Duplicate type name within an assembly.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentException: Duplicate type name within an assembly.]
System.Reflection.Emit.AssemblyBuilderData.CheckTy peNameConflict(String strTypeName, TypeBuilder enclosingType) +311
System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +176
System.Reflection.Emit.TypeBuilder..ctor(String name, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, TypeBuilder enclosingType) +28
System.Reflection.Emit.ModuleBuilder.DefineType(St ring name, TypeAttributes attr, Type parent) +88
Spring.Proxy.CompositionProxyTypeBuilder.CreateTyp eBuilder() +75
Spring.Proxy.CompositionProxyTypeBuilder.BuildProx y() +39
Spring.Web.Services.WebServiceExporter.AfterProper tiesSet() +132
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) +176
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +958

[ObjectCreationException: Error creating object with name 'BC.Contact' defined in 'file [C:\Views\BC20_July\Business_Center\Services\xo.Co mmon.Services\Config\AccountManagement\AccountMana gement.xml]' : Initialization of object failed : Duplicate type name within an assembly.]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +1087
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) +17
Spring.Objects.Factory.Support.AbstractObjectFacto ry.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +224
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) +301
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) +30
Spring.Objects.Factory.Support.DefaultListableObje ctFactory.PreInstantiateSingletons() +496
Spring.Context.Support.AbstractApplicationContext. Refresh() +787
Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations) +37

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.Reflection.RuntimeConstructorInfo.InternalI nvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault) +0
System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +398
Spring.Objects.ObjectUtils.InstantiateType(Constru ctorInfo constructor, Object[] arguments) +46

[FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.']
Spring.Context.Support.WebApplicationContext.get_C urrent() +217
Spring.Web.Services.WebServiceHandlerFactory.Syste m.Web.IHttpHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path) +68
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +696
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute() +95
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +173





Any ideas?

Thanks for help!

Tony

Bruno Baia
04-13-2006, 09:43 AM
I want to apply the Log4NetLoggingAroundAdvice to my web service.


You can't apply an advice on a web service, u have to apply your advices to the service, then export the service proxied as a web service :
- Apply advices to your service using "Spring.Aop.Framework.ProxyFactoryObject"
- Export your proxied service as a Web service using "Spring.Web.Services.WebServiceExporter"


<objects xmlns="http://www.springframework.net">

<object id="Log4NetLoggingAroundAdvice" type="Aspects.Logging.Log4NetLoggingAroundAdvice, Aspects">
<property name="Level" value="Debug" />
</object>





<object id="getContact" type="xo.Common.Services.AccountManagement.xoContact, xo.Common.Services.BC"/>


<object id="getContact.Aop" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="target" ref="getContact"/>
<property name="interceptorNames">
<list>
<value>Log4NetLoggingAroundAdvice</value>
</list>
</property>
</object>


<object id="BC.Contact" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="getContact.Aop" />

<property name="Interfaces" >
<list>
<value>xo.Common.Interfaces.AccountManagement.IContact, xo.Common.Interfaces.BC</value>
</list>
</property>
</object>



</objects>



-Bruno

tdu
04-13-2006, 04:22 PM
It worked. Thanks for the help.

Tony