Issue with Property Injection, Policy Injection and the Service Collection

Topics: Web Client Software Factory, User Forum
Apr 7, 2008 at 4:35 PM
Edited Apr 7, 2008 at 4:36 PM
Hello All,

I am recieving an AccessViolationException when I try to add a service to the globalServices Collection. This occurs when the service has been wrapped using Policy Injection and has a dependency injected via a property.

I have a couple of work arounds for this 1. Use Constructor Injection, 2. Inherit from MarshalByRefObject. However, I would prefer to use Property Injection.

This only occurs when I am adding the Transparent Proxy to the services collection.

Is this an issue that can be corrected? Are there other workarounds?

I am using version 2.0.2.0 of the CompositeWeb.

What I have is this:

Public Interface IMyService
End Interface

Public Class MyService
Implements IMyService

Private _traceService As Tracing.ITraceService

<ServiceDependency()> _
Public Property TraceService() As Tracing.ITraceService
Get
Return _traceService
End Get
Set(ByVal value As Tracing.ITraceService)
_traceService = value
End Set
End Property

End Class

In the ModuleInitializer Load:

Dim instance As IMyService= container.BuildNewItem(GetType(MyService))
Dim proxy As IMyService = PolicyInjection.Wrap(Of IMyService)(instance)
serviceCollection.Add(Of IMyService)(proxy)

The Error Messages and Stack Trace are below.

Thank you,

Jeff

AccessViolationException

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

" at Microsoft.Practices.ObjectBuilder.BuilderAwareStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.CompositeWeb.BuilderStrategies.SessionStateBindingStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.BuildPlanStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.CompositeWeb.ObjectBuilder.Strategies.SimplifiedSingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.CompositeWeb.BuilderStrategies.ContainerAwareTypeMappingStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.CompositeWeb.ObjectBuilder.WCSFBuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.CompositeWeb.ObjectBuilder.WCSFBuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.BuildFirstTimeItem(Type typeToBuild, Type typeToRegisterAs, Object item)
at Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Build(Type typeToBuild, Type typeToRegisterAs, Object serviceInstance)
at Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Add(Type serviceType, Object serviceInstance)
at Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.AddTService(TService serviceInstance)
at ERA.MyTE.MyTEModuleInitializer.RegisterServiceTServiceInterface,TServiceImplementation(IServiceCollection serviceCollection) in MyTEModuleInitializer.vb:line 76
at ERA.MyTE.MyTEModuleInitializer.AddGlobalServices(IServiceCollection globalServices) in MyTEModuleInitializer.vb:line 40
at ERA.MyTE.MyTEModuleInitializer.Load(CompositionContainer container) in MyTEModuleInitializer.vb:line 29
at Microsoft.Practices.CompositeWeb.Services.ModuleLoaderService.Load(CompositionContainer rootContainer, IModuleInfo[] modulesInfo)"
Coordinator
Apr 8, 2008 at 1:21 AM
I asked Chris Tavares (PIAB author) to help you out. Look for a response soonish from him.

Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/
Apr 8, 2008 at 4:49 AM
This will take a while to get set up on my box. Is there any chance you could send me a ready-to-go small repro case?

Thanks,

-Chris
Apr 23, 2008 at 1:56 PM
Yes, I can. Should I email it to you?

-Jeff
Coordinator
Apr 23, 2008 at 9:59 PM
Send it to either Chris or myslef via the Contact link on our profiles.

Thanks,
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
Nov 4, 2011 at 5:25 PM

Any luck with this issue?

Jan 13, 2012 at 9:41 PM

nuchild,

I'm not sure if Michael or Chris have received a sample regarding this.  Are you running into the same problem? 

Bob

Mar 27, 2012 at 3:17 PM
Edited Mar 27, 2012 at 3:18 PM

Hello Brumfb,

I am running into the same problem.

But unfortunately, I can't tell what/when is the root of the problem yet exactly. I only noticed when I moved my code to production. As long as the code was running out of Visual Studio it was okay. Until I put it in IIS.

I could send my code to you if you'd like. I have no qualms about that.

Mar 27, 2012 at 3:34 PM
Edited Mar 27, 2012 at 3:35 PM

Hello,

In the meantime, please find the error below.

 

Server Error in '/test_inventory' Application.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

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.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

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:

[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
   BuildUp_securityadmin.securityadminController(IBuilderContext , Type , Object , String ) +0
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.DynamicMethodPlan.DynamicMethodBuildPlan.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String id) +63
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.BuildPlanStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +81
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.ObjectBuilder.Strategies.SimplifiedSingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +245
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +278
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.BuilderStrategies.ContainerAwareTypeMappingStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +255
   BuildUp_it_asset_inventory.securityadmin.Views.ManageUsersPresenter(IBuilderContext , Type , Object , String ) +62
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.DynamicMethodPlan.DynamicMethodBuildPlan.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String id) +63
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.BuildPlanStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +81
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.ObjectBuilder.Strategies.SimplifiedSingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +245
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +278
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.BuilderStrategies.ContainerAwareTypeMappingStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +255
   BuildUp_ASP.securityadmin_manageusers_aspx(IBuilderContext , Type , Object , String ) +75
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.DynamicMethodPlan.DynamicMethodBuildPlan.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String id) +63
   Microsoft.Practices.CompositeWeb.ObjectBuilder.BuildPlan.BuildPlanStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +81
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.ObjectBuilder.Strategies.SimplifiedSingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +245
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +278
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.CompositeWeb.BuilderStrategies.ContainerAwareTypeMappingStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +289
   Microsoft.Practices.CompositeWeb.ObjectBuilder.WCSFBuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +139
   Microsoft.Practices.CompositeWeb.ObjectBuilder.WCSFBuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +55
   Microsoft.Practices.CompositeWeb.CompositionContainer.BuildItem(IBuilder`1 builder, IReadWriteLocator locator, Object item) +411
   Microsoft.Practices.CompositeWeb.WebClientApplication.BuildItemWithCurrentContext(Object obj) +187
   Microsoft.Practices.CompositeWeb.Web.UI.Page.OnPreInit(EventArgs e) +46
   System.Web.UI.Page.PerformPreInit() +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282
Mar 28, 2012 at 7:01 PM

Hi,

As far as I know, the AccessViolationException is a low-level exception which indicates that an unmanaged pointer is trying to access memory that it doesn't have the permission to. There are several scenarios where this exception could appear, mainly when involving unmanaged code like calls to native dlls. It seems that this error is not specifically related to any product, library, guidance or technology.

You can find more information about this exception in the following link:

Also, I believe you might find the following discussion in the MSDN forums useful, where several scenarios in which this exception appears are portrayed and discussed:

If you wish to be able to catch this exception (in order to obtain more information of what might be causing it or for other purposes) you could try surrounding the line that is throwing the exception in a try -  catch block and marking the method containing it with the HandleProcessCorruptedStateExceptions attribute. You can find more information about handling corrupted state exceptions (CSE) in the following blog post:

As a side note,  if you are using the .NET Framework 2.0 version, there is a know issue where an AccessViolationException might be thrown depending of the environment where the application is running:

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Mar 29, 2012 at 8:08 AM

Hi DCherubini. 

Thanks for the response. 

Actually, this issue has kind of disappeared. :)

I agree with your position. I may take the time to attempt to reproduce the issue if I have time and see exactly what was happening but

it appears it had to do with DLLs for my build of WCSFContrib.

I noticed I had both the objectbuilder.dll (entlib 3.1) and objectbuilder2.dll (entlib 4.1) DLLs in my project.

Apparently, My WCSF though it emits Entlib 4.1 libraries still adds the objectuilder.dll into the mix.

I intend to modify the wcsf files and rebuild so objectbuilder.dll is not included.

It would be nice to be able to download a build from this site that is actually meant for ent lib 4.1 from the get go.

As it seems project silk and by inference asp.net mvc (can we expect an asp.net mvc 4 without breaking changes?) is the new way to go.

Could you guys provide some guidance on migrating from wcsf to silk? Or maybe everyone's meant to develop on sharepoint? :)

Thanks