tags:

views:

42

answers:

1

I have a piece of code that I can run in four ways

  1. Debug build - in the debugger - works just fine

  2. Debug build - outside debugger - fails

  3. Release build - in the debugger - fails

  4. Release build - outside debugger - fails.

The error code is gives in all cases is 202 - something to do with parameterless constructors, call stack at the bottom.

It fails at the same point in each case, when it is building the first object it is asked for.

I can't build the source with debug because I am using .Net 4.0 and don't seem to have the .Net 2.0 SDK installed in order to build it.

I am starting to run out of ideas....

Exception:

Test method DataLoaders.Integration.ContactMappingTests.EntityContactMappingTest threw exception: 
StructureMap.StructureMapException: StructureMap Exception Code:  202
No Default Instance defined for PluginFamily System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Callstack:

StructureMap.BuildSession.<.ctor>b__0(Type t)
StructureMap.Util.Cache`2.get_Item(KEY key)
StructureMap.BuildSession.CreateInstance(Type pluginType)
StructureMap.Pipeline.DefaultInstance.build(Type pluginType, BuildSession session)
StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session)
StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session)
StructureMap.Pipeline.ConstructorInstance.Get[T](String propertyName, BuildSession session)
StructureMap.Pipeline.Arguments.Get[T](String propertyName)
lambda_method(Closure , IArguments )
StructureMap.Construction.BuilderCompiler.FuncCompiler`1.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args)
StructureMap.Construction.InstanceBuilder.BuildInstance(IArguments args)
StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder)
StructureMap.Pipeline.ConstructorInstance.build(Type pluginType, BuildSession session)
StructureMap.Pipeline.SmartInstance`1.build(Type pluginType, BuildSession session)
StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session)
StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session)
StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session)
StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance)
StructureMap.BuildSession.<>c__DisplayClass3.<.ctor>b__1()
StructureMap.BuildSession.CreateInstance(Type pluginType)
StructureMap.Container.GetInstance[T]()
StructureMap.ObjectFactory.GetInstance[PLUGINTYPE]()
DataLoaders.Processor.ProcessData(DataConfig config) in D:\TFS\Main\Source\DataLoaders\DataLoaders\Processor.cs: line 20
+1  A: 

I can't explain why it works in one case and not the others.

However, I would start with looking at the System.Uri class. 4.0 added constructors to the class, which would absolutely change the way it gets resolved by the container. I believe that StructureMap will always try to use the greediest constructor by default.

The API may have changed since this post, but this get your started at least: http://codebetter.com/blogs/jeremy.miller/archive/2009/01/07/choosing-the-constructor-function-in-structuremap-without-attributes.aspx

Phil Sandler
Well done, I didn't think we'd used Uri's anywhere so ignored the comment as some spurious StructureMap string.
Colin Desmond