Release build of application fails

Mar 5, 2009 at 4:36 PM
Hi,

We are currently having a huge problem with our application using unity. It seems that when the application is compiled in debug mode all is working correctly, but when we try to create a release build we are getting 

2009-03-05 17:23:40,468 [1] ERROR Pdc.Erp.Application.Win.Shell - Resolution of the dependency failed, type = "Pdc.Erp.Application.Core.Presenters.Transportation.ITransporterPresenter", name = "". Exception message is: The current build operation (build key Build Key[Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter, null]) failed: The parameter context could not be resolved when attempting to call constructor Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(Pdc.Erp.Application.Core.Views.Transportation.ITransporterView view, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[[Pdc.Erp.Model.Domain.Transportation.Transporter, Pdc.Erp.Model.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] context). (Strategy type BuildPlanStrategy, index 4)
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Pdc.Erp.Application.Core.Presenters.Transportation.ITransporterPresenter", name = "". Exception message is: The current build operation (build key Build Key[Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter, null]) failed: The parameter context could not be resolved when attempting to call constructor Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(Pdc.Erp.Application.Core.Views.Transportation.ITransporterView view, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[[Pdc.Erp.Model.Domain.Transportation.Transporter, Pdc.Erp.Model.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] context). (Strategy type BuildPlanStrategy, index 4) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter, null]) failed: The parameter context could not be resolved when attempting to call constructor Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(Pdc.Erp.Application.Core.Views.Transportation.ITransporterView view, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[[Pdc.Erp.Model.Domain.Transportation.Transporter, Pdc.Erp.Model.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] context). (Strategy type BuildPlanStrategy, index 4) ---> System.InvalidOperationException: The parameter context could not be resolved when attempting to call constructor Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(Pdc.Erp.Application.Core.Views.Transportation.ITransporterView view, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[[Pdc.Erp.Model.Domain.Transportation.Transporter, Pdc.Erp.Model.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] context). ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], null]) failed: The current type, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 4) ---> System.InvalidOperationException: The current type, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], is an interface and cannot be constructed. Are you missing a type mapping?
   bij Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:regel 174
   bij BuildUp_Pdc.Erp.Application.Core.Contexts.IEntityContext`1[[Pdc.Erp.Model.Domain.Transportation.Transporter, Pdc.Erp.Model.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](IBuilderContext )
   bij Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:regel 40
   bij Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:regel 86
   --- Einde van intern uitzonderingsstackpad ---
   bij Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:regel 109
   bij Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\Unity\ObjectBuilder\NamedTypeDependencyResolverPolicy.cs:regel 52
   bij BuildUp_Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(IBuilderContext )
   --- Einde van intern uitzonderingsstackpad ---
   bij Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:regel 154
   bij BuildUp_Pdc.Erp.Application.Presentation.Transportation.TransporterPresenter(IBuilderContext )
   bij Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:regel 40
   bij Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:regel 86
   --- Einde van intern uitzonderingsstackpad ---
   bij Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:regel 109
   bij Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\ObjectBuilder\Builder.cs:regel 61
   bij Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\Unity\UnityContainer.cs:regel 463
   --- Einde van intern uitzonderingsstackpad ---
   bij Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\Unity\UnityContainer.cs:regel 473
   bij Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name) in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\Unity\UnityContainer.cs:regel 155
   bij Microsoft.Practices.Unity.UnityContainerBase.Resolve[T]() in e:\Builds\Unity\UnityTemp\Compile\Unity\Src\Unity\UnityContainerBase.cs:regel 466
   bij Objective.Core.IoC.Unity.UnityDependencyResolver.Resolve[T](ITypeInstancePair[] typeInstancePairs) in c:\BuildFolder\Objective.Trunk\WorkingDirectory\src\Objective.Core.IoC.Unity\UnityDependencyResolver.cs:regel 273
   bij Objective.Core.IoC.Dependency.Resolve[T](ITypeInstancePair[] typeInstancePairs) in c:\BuildFolder\Objective.Trunk\WorkingDirectory\src\Objective.Core\IoC\Dependency.cs:regel 192
   bij Pdc.Erp.Application.Win.Controllers.ScreenController.GetPresenter[TPresenter,TContext](TContext context) in C:\Projects\Pdc.Erp\src\Pdc.Erp.Application.Win\Controllers\ScreenController.cs:regel 235
   bij Pdc.Erp.Application.Win.Controllers.ScreenController.Show[T,C](C context) in C:\Projects\Pdc.Erp\src\Pdc.Erp.Application.Win\Controllers\ScreenController.cs:regel 205
   bij Pdc.Erp.Application.Win.Controllers.ScreenController.ShowSingleton[T,C](ScreenMode mode, C context) in C:\Projects\Pdc.Erp\src\Pdc.Erp.Application.Win\Controllers\ScreenController.cs:regel 219
   bij Pdc.Erp.Application.Win.Controllers.ScreenController.Show[TPresenter,TContext](ScreenMode mode, TContext context) in C:\Projects\Pdc.Erp\src\Pdc.Erp.Application.Win\Controllers\ScreenController.cs:regel 188
   bij Pdc.Erp.Application.Win.Commands.Transportation.EditTransporter.Execute(Transporter instance) in C:\Projects\Pdc.Erp\src\Pdc.Erp.Application.Win\Commands\Transportation\EditTransporter.cs:regel 26
   bij Objective.Core.MVP.Win.Actions.NamedCommandControllerImpl`1.Execute(T instance) in c:\BuildFolder\Objective.Trunk\WorkingDirectory\src\Objective.Core.MVP.Win\Actions\NamedCommandControllerImpl.cs:regel 132
   bij Objective.Core.MVP.Win.Actions.ActionItemControllerImpl`1.OnControlClickedFired(Object sender, EventArgs e) in c:\BuildFolder\Objective.Trunk\WorkingDirectory\src\Objective.Core.MVP.Win\Actions\ActionItemControllerImpl.cs:regel 110
   bij System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   bij Objective.Core.Controls.Win.ToolStripButtonShortcut.OnParentFormKeyDownFired(Object sender, KeyEventArgs e) in c:\BuildFolder\Objective.Trunk\WorkingDirectory\src\Objective.Core.Controls.Win\ToolStripButtonShortCut.cs:regel 54
   bij System.Windows.Forms.KeyEventHandler.Invoke(Object sender, KeyEventArgs e)
   bij System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   bij System.Windows.Forms.Form.ProcessKeyPreview(Message& m)
   bij System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   bij System.Windows.Forms.Control.WmKeyChar(Message& m)
   bij System.Windows.Forms.Control.WndProc(Message& m)
   bij System.Windows.Forms.DataGridView.WndProc(Message& m)
   bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   bij System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

What we are doing in the code here is trying to resolve a presenter, which has a dependency to a context and a view
The context part is injected trough the use of a childcontainer with a registerinstance.

Can't seem to get my head around this issue anyone has any bright ideas

Kind regards
Mar 5, 2009 at 7:37 PM

Something to try (since it compiles in Debug).  Copy/paste the contents of the Debug folder into the Release folder then rebuild solution in Release. Cheesy I know but I ran across this in a prior contract and it got us through a compile and then it would just keep working.

 

I saw something like the following when I was trying to resolve my data access layer (which had an “Add Web Service” web reference to my WCF Service – for some reason when my IDAL was being resolved it was trying to resolve an interface within my Web Service.   Time constraints had me manually instantiate my Data Layer, passing in a container in the constructor – versus using constructor injection, my constructor then set all my interfaces via the unity container passed in as applicable.   Since your not having the problem in debug it may be a mute point to mention it but at times like this any clue might help...

 

---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], null]) failed: The current type, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 4) ---> System.InvalidOperationException: The current type, Pdc.Erp.Application.Core.Contexts.IEntityContext`1[Pdc.Erp.Model.Domain.Transportation.Transporter], is an interface and cannot be constructed. Are you missing a type mapping?

Good luck!

Bill

 

Mar 5, 2009 at 11:04 PM
It's a bit weird that it would work in release and not in debug. Does it work in release mode if you attach a debugger to it?

The first thing I'd check is the what the error message is telling you - are you sure the type mapping is in place? Are you pulling from a different config file somehow? Or has the assembly identity changed and it can't find the type anymore?

Really hard to tell without a repro case.

Mar 6, 2009 at 8:20 AM
First of all thanks for all the replies :)

Neither of the proposed workarounds work, i will try to get a repro case running, what i am sure of is that it got something to do with a childcontainer with in his parent an open generic type mapped IEntityContext. Could it have something to do with the with the code optimization in release mode, because when i run in straight from the debug folder it also works, which i find very strange. I saw a post yesterday about an ILogging extension on Entlib 4.1 where they also got some sort of an issue related to a jit bug with dynamic method invocations.

What i can say for now is that i hate these sort of issues :(
Mar 6, 2009 at 11:24 AM
Ok found out more, it seems all depending on 1 tiny little checkbox in your release build properties "Optimize Code". when i uncheck this it works also in release mode, for now this can be a workaround, but it seems to indicate a problem more or less related to http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=29005. As it is more or less the same error and problem.

They quick fixed it with [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] above the constructor, but in the current source of entlib i didn't see it anymore.

Anyone has got a clue ?
Mar 7, 2009 at 9:25 AM
Hi again,

Yet another update, i got it fixed. But i don't understand why it fixes it. So now i can build a release compile with optimize code on solong as i put a try-catch or try-finally around the code. So indeed it seems a optimization in msil related problem.
If i look at the code in ildasm i only see as a difference the save boxing of the objects as objects.

I don't understand the solution though.