Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.InvalidOperationException: variable ... of type AgileObjects.AgileMapper.ObjectPopulation.IObjectMappingData ... but is not defined #174

Closed
bslbckr opened this issue Nov 12, 2019 · 5 comments
Assignees
Labels
bug in-preview A feature or bug fix exists in a preview release, and a full release will follow

Comments

@bslbckr
Copy link

bslbckr commented Nov 12, 2019

Using the freshly provided 1.6.0-preview4 version of the mapper I ran into the above mentioned exception using a relatively simple object structure. I tried to map the following classes:

namespace Src {
	public class Definition {
		public enum Scope {
			GLOBAL, LANE, INDEX			
		}
		public string Identification {get;set;}
		public string Unit {get;set;}
		public IList<int> UnavailableNumbers {get;set;}
		public Scope DefScope {get;set;}
		public object Min {get;set;}
		public object Max {get;set;}
	}
}

namespace Tgt {
  public class ParamDef {
	  public enum Scope {
		  STH, COMPLETELY, DIFFERENT
	  }
	  public string Identification {get;set;}
	  public string Unit {get;set;}
	  public IList<int> UnavailableNumbers{get;set;}
	  public Scope DefScope {get;set;}
	  public Wrapper Min {get;set;}
	  public Wrapper Max {get;set;}
  }
	
	public class Wrapper {
		public int IntVal {get;set;}
		public bool BoolVal {get;set;}
		public string StringVal {get;set;}
		public double DoubleVal {get;set;}
	}
}

from namespace Src to namespace Tgt using the following mapping-specification:

Mapper.WhenMapping.PairEnums<Src.Definition.Scope>(new [] {Src.Definition.Scope.GLOBAL, Src.Definition.Scope.LANE, Src.Definition.Scope.INDEX}).With<Tgt.ParamDef.Scope>(new [] {Tgt.ParamDef.Scope.STH, Tgt.ParamDef.Scope.COMPLETELY, Tgt.ParamDef.Scope.DIFFERENT});
Mapper.WhenMapping.From<int>().To<Tgt.Wrapper>().Map(input => input, tgt => tgt.IntVal);

If I omit the Min and Max members, the mapping works flawlessly. However, if I include them I receive the following exception:

[System.InvalidOperationException: variable 'dToPdData' of type 'AgileObjects.AgileMapper.ObjectPopulation.IObjectMappingData`2[Src.Definition,Tgt.ParamDef]' referenced from scope '', but it is not defined]
   at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
   at System.Linq.Expressions.ParameterExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node)
   at System.Linq.Expressions.ConditionalExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitTry(TryExpression node)
   at System.Linq.Expressions.TryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
   at System.Linq.Expressions.Expression`1.Compile()
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMapper`2..ctor(Expression mapping, IObjectMappingData mappingData)
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMapperFactory.Create[TSource,TTarget](ObjectMappingData`2 mappingData)
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData`2.GetOrCreateMapper()
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMapper`2.<>c.<MapSubObject>b__18_0(ObjectMapperKeyBase key)
   at AgileObjects.AgileMapper.Caching.ArrayCache`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMapper`2.MapSubObject(IObjectMappingData mappingData)
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData`2.Map[TDeclaredSource,TDeclaredTarget](TDeclaredSource sourceValue, TDeclaredTarget targetValue, String targetMemberRegistrationName, Int32 dataSourceIndex)
   at lambda_method(Closure , IObjectMappingData`2 )

[AgileObjects.AgileMapper.MappingException: An exception occurred mapping Definition -> ParamDef with rule set CreateNew.]
   at lambda_method(Closure , IObjectMappingData`2 )
   at AgileObjects.AgileMapper.ObjectPopulation.ObjectMapper`2.Map(ObjectMappingData`2 mappingData)
   at AgileObjects.AgileMapper.MappingExecutor`1.PerformMapping[TTarget](TTarget target)
   at AgileObjects.AgileMapper.MappingExecutor`1.PerformMapping[TTarget](MappingRuleSet ruleSet, TTarget target)
   at AgileObjects.AgileMapper.MappingExecutor`1.ToANew[TResult]()
   at Program.Main() :line 50

The complete example could be found in this fiddle

@SteveWilkes SteveWilkes self-assigned this Nov 13, 2019
@bslbckr
Copy link
Author

bslbckr commented Nov 27, 2019

Any news on this one?
Is there anything I could help with? e.g. writing a pr with an appropriate Unit-Test for this issue or sth similar?

@SteveWilkes
Copy link
Member

Hi!

Sorry for the delay - I've not got around to looking at this yet. I will, and will report back.

Cheers,

Steve

SteveWilkes added a commit that referenced this issue Nov 29, 2019
SteveWilkes added a commit that referenced this issue Nov 29, 2019
@SteveWilkes
Copy link
Member

This is fixed in the latest v1.6 branch code - release to follow! Cheers! :)

@SteveWilkes
Copy link
Member

This fix is included in v1.6-preview5, now available on NuGet. Thanks again!

@SteveWilkes SteveWilkes added bug in-preview A feature or bug fix exists in a preview release, and a full release will follow labels Nov 30, 2019
@SteveWilkes
Copy link
Member

The fix for this is included in v1.6, which is now available on NuGet.

Thanks again for the feedback!

SteveWilkes added a commit that referenced this issue Feb 16, 2020
* Updating to v1.6

* Fixing numeric to non-int-derived enum mapping

* v1.6-preview1 NuGet package

* Mapping non-mappable-element enumerables to empty collections

* Support for type-pairing using interfaces, re: #163

* v1.6-preview2

* Adding project icon

* Bugs/issue163 (#164)

* Adding .NET Core 3 test project

* Removing assembly scanning for interfaces / Handling interface -> implementation type pairing / Tidying

* Removing issue-specific test + updating .NET Core 3 package versions

* Updating icon, adding v1.6-preview3 package

* Tidying

* Tidying

* Tidying

* Splitting Root- and MemberDataSourceSetFactories

* Adding EmptyDataSourceSet / Filtering out unusable fallback data sources in DataSourceSet factory method instead of MemberPopulator

* Making EmptyDataSourceSet a singleton / Adding NullMemberPopulator

* Removing IEnumerable from IDataSourceSet

* Extending interface mapping test coverage

* Fixing .NET 3.5 source filters

* Features/simple type create instances using (#169)

* Failing unit test / Simplifying configured factory creation

* Tidying

* Support for configured object factories for simple (not primitive) types, re: #165

* Splitting out incorrect object factory configuration tests

* Removing unnecessary ignore from test

* Implementing simple type factories using ObjectFactories

* Adding lightweight IMemberMapperData implementation

* Creating element mapper data when using a configured simple type object factory for an enumerable element

* Support for simple type factory use in simple type enumerable mapping

* Support for conditional simple-type factories / Splitting simple-type factory tests into dedicated test class

* Support for conditional simple value factories with fallback to default conversion

* Support for simple type factory Funcs

* Support for nullable simple type factories

* Optimising simple type factory expression creation

* Test coverage for nullable simple type to simple type factory / Support for TimeSpan mapping (?!)

* Handling nested access checks in nullable-to-simple type factory use

* TimeSpan mapping test coverage

* Fixing test for .NET 3.5

* Adding package icon setting

* Bugs/issue166 (#170)

* Only populating MapperDatas in maptime-created ObjectMappingDatas if necessary + available, re: #166

* Renames for clarity

* Tidying

* Updating release notes

* Fixing translation of mapping plans with assignment of a local enum variable, re: #168 (#171)

Using GetVariableNameInCamelCase() for multi-invocation local variables

* Only creting a mapping LambdaExpression when necessary

* Organising mapping data source factory classes

* Tidying

* Updating to v1.6-preview4

* Lazy-loading ObjectMapperData ChidMapperData and DataSourcesByTargetMember

* Replacing Dictionary<,> with simple array-based alternative

* General tidying

* Ensuring root mapping plans include the mapper func parameter

* Removing capture creation in QualifiedMember pathfactories

* Using less derived parameter types

* Handling runtime-typed, simple-to-complex data sources configured using Map(s => s, t=> t), re: #174 (#177)

* Features/element index (#178)

* Renaming EnumerableIndex to ElementIndex

* Adding ElementKey through, adding failing test

* Support for ElementKey!

* Support for ElementKey with element-value-typed source Dictionaries

* Extra test coverage

* Updating to v1.6-preview5

* Type-Specific naming rules in the static API (#181)

* Fixing API / Adding ConfiguredNamingPattern / Adding type-specific naming tests

* Tidying

* Updating naming settings to be non-ruleset-specific

* Moving MapperContext into BasicMapperData

* Tidying

* Renaming BasicMapperData

* Setting QualifiedMemberContext on members

* Fixing tests

* Updating documentation

* Updating release notes

* Bugs/183 abstract member validation (#185)

* Support for applying custom data sources to base types only
* Improved detection of unmappable target types in mapping validation
* Tidying

* Extra test coverage

* Explicit support for DateTimeOffset mapping, re: #183

* Counting System.Drawing as a Base Class Library, re: #180

* Removing root source dynamic mapping tests from .NET Standard 1.0, re: #183

* Features/derived type mapping improvements (#186)

* Support for using MapTo() without specifying a derived source type, re: #172
* Test coverage for nested interface type pairing, re: #172

* Bugs/176 complex type data source method (#187)

* Adding failing tests re: using a custom method as a data source for a complex type

* Splitting NestedAccessCheck finding and Multi-invocation finding / Moving multi-invocation handling to MemberPopulator

* Making ExpressionInfoFinder static

* Moving multi-invocation handling back into DataSourceBase

* Applying multi-invocation replacements to DataSourceBase populations

* Handling assignment of chained multi-invocation variables / Optimising Expression replacement

* Handling null return values from custom object factories / Optimising Member Binding generation

* Registering static method complex type data sources as factoey methods

* Optimising for single multi-invocation

* Tidying

* Processing multi-invocations in DataSource finalisation

* Revert "Processing multi-invocations in DataSource finalisation"

This reverts commit 5312747.

* Avoiding multi-invocation processing of alternate population branches

* Processing multi-invocations in DataSource finalisation

* Skipping multi-invocation checks for composite data source value expressions
Optimising empty child mapper data collection access

* Fixing .NET 3.5 invocation comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug in-preview A feature or bug fix exists in a preview release, and a full release will follow
Projects
None yet
Development

No branches or pull requests

2 participants