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

FieldAccessException on accessing Postgres table from DbMetal-generated code #156

Closed
GoogleCodeExporter opened this issue Apr 24, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

After manually fixing issue 155 the code generated by DbMetal compiles, but
fails at runtime.

What steps will reproduce the problem?

1. Use DbMetal to generate code from a Postgres database (see attached
extract, which contains the code for one table).
2. Run a program that tries to access the table, eg.

var conn = new NpgsqlConnection(connString);
var db = new SgaDev(conn);
db.Countries.ToArray();

What is the expected output? What do you see instead?

Expected: results are returned.
Actual: the following exception is thrown:

System.FieldAccessException: Field `Countries:_countryCode' is inaccessible
from method `(wrapper dynamic-method) object:setter (Countries,string)'

  at (wrapper managed-to-native) System.Delegate:CreateDelegate_internal
(System.Type,object,System.Reflection.MethodInfo)
  at System.Delegate.CreateDelegate (System.Type type, System.Object
firstArgument, System.Reflection.MethodInfo method, Boolean
throwOnBindFailure) [0x00251] in
/var/install/mono-2.4.2.3/mcs/class/corlib/System/Delegate.cs:256 
  at System.Delegate.CreateDelegate (System.Type type,
System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000]
in /var/install/mono-2.4.2.3/mcs/class/corlib/System/Delegate.cs:278 
  at System.Delegate.CreateDelegate (System.Type type,
System.Reflection.MethodInfo method) [0x00000] in
/var/install/mono-2.4.2.3/mcs/class/corlib/Assembly/AssemblyInfo.cs:1 
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type
delegateType) [0x00023] in
/var/install/mono-2.4.2.3/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.
cs:174

  at DbLinq.Data.Linq.Mapping.LambdaMetaAccessor.MakeSetter
(System.Reflection.MemberInfo member, System.Type memberType, System.Type
declaringType) [0x000ee] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/LambdaMetaAccessor.cs:44

  at DbLinq.Data.Linq.Mapping.LambdaMetaAccessor.Create
(System.Reflection.MemberInfo member, System.Type declaringType) [0x00085]
in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/LambdaMetaAccessor.cs:73

  at DbLinq.Data.Linq.Mapping.AttributedAbstractMetaDataMember..ctor
(System.Reflection.MemberInfo member, System.Data.Linq.Mapping.MetaType
declaringType, System.Data.Linq.Mapping.DataAttribute attribute) [0x00053]
in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/AttributedAbstractMetaDat
aMember.cs:46

  at DbLinq.Data.Linq.Mapping.AttributedColumnMetaDataMember..ctor
(System.Reflection.MemberInfo member,
System.Data.Linq.Mapping.ColumnAttribute attribute,
System.Data.Linq.Mapping.MetaType declaringType) [0x00000] in
/var/install/dblinq/trunk/src/DbLinq.ProductInfo.cs:1 
  at DbLinq.Data.Linq.Mapping.AttributedMetaType.<get_DataMembers>m__F
(.<>__AnonType0`2 <>__TranspIdent0) [0x00000] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/AttributedMetaType.cs:115

  at
System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[<>__AnonType0`2[Sys
tem.Reflection.MemberInfo,System.Data.Linq.Mapping.ColumnAttribute],System.Data.
Linq.Mapping.MetaDataMember].MoveNext
() [0x00000] 
  at
System.Collections.Generic.List`1[System.Data.Linq.Mapping.MetaDataMember].AddEn
umerable
(IEnumerable`1 enumerable) [0x00000] 
  at
System.Collections.Generic.List`1[System.Data.Linq.Mapping.MetaDataMember]..ctor
(IEnumerable`1 collection) [0x00000] 
  at System.Linq.Enumerable.ToList[MetaDataMember] (IEnumerable`1 source)
[0x00000] 
  at DbLinq.Data.Linq.Mapping.AttributedMetaType.get_DataMembers ()
[0x0000b] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/AttributedMetaType.cs:111

  at DbLinq.Data.Linq.Mapping.AttributedMetaType.get_PersistentDataMembers
() [0x0000b] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Mapping/AttributedMetaType.cs:250

  at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher+<RegisterAllColumns>c
__Iterator1A.MoveNext
() [0x00023] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/ExpressionDi
spatcher.Registrar.cs:338

  at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.GetOutputTableReader
(DbLinq.Data.Linq.Sugar.Expressions.TableExpression tableExpression,
System.Linq.Expressions.ParameterExpression dataRecordParameter,
System.Linq.Expressions.ParameterExpression mappingContextParameter,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x0006f] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/ExpressionDi
spatcher.Registrar.cs:386

  at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.CutOutOperands
(System.Linq.Expressions.Expression expression,
System.Linq.Expressions.ParameterExpression dataRecordParameter,
System.Linq.Expressions.ParameterExpression mappingContextParameter,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x00019] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/ExpressionDi
spatcher.cs:177

  at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.CutOutOperands
(System.Linq.Expressions.Expression selectExpression,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x0002a] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/ExpressionDi
spatcher.cs:152

  at DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.BuildSelect
(System.Linq.Expressions.Expression selectExpression,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x00038] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/ExpressionDi
spatcher.cs:106

  at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery
(DbLinq.Data.Linq.Sugar.ExpressionChain expressions,
System.Linq.Expressions.Expression tableExpression,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x00010] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/QueryBuilder
.cs:204

  at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery
(DbLinq.Data.Linq.Sugar.ExpressionChain expressions,
DbLinq.Data.Linq.Sugar.BuilderContext builderContext) [0x00019] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/QueryBuilder
.cs:182

  at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery
(DbLinq.Data.Linq.Sugar.ExpressionChain expressions,
DbLinq.Data.Linq.Sugar.QueryContext queryContext) [0x00007] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/QueryBuilder
.cs:76

  at DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.GetSelectQuery
(DbLinq.Data.Linq.Sugar.ExpressionChain expressions,
DbLinq.Data.Linq.Sugar.QueryContext queryContext) [0x00030] in
/var/install/dblinq/trunk/src/DbLinq/Data/Linq/Sugar/Implementation/QueryBuilder
.cs:393

  at DbLinq.Data.Linq.Implementation.QueryProvider`1[Countries].GetQuery
(System.Linq.Expressions.Expression expression) [0x00000] 
  at
DbLinq.Data.Linq.Implementation.QueryProvider`1[Countries].GetEnumerator ()
[0x00000] 
  at DbLinq.Data.Linq.Table`1[Countries].GetEnumerator () [0x00000] 
  at
DbLinq.Data.Linq.Table`1[Countries].System.Collections.Generic.IEnumerable<TEnti
ty>.GetEnumerator
() [0x00000] 
  at System.Collections.Generic.List`1[Countries].AddEnumerable
(IEnumerable`1 enumerable) [0x00000] 
  at System.Collections.Generic.List`1[Countries]..ctor (IEnumerable`1
collection) [0x00000] 
  at System.Linq.Enumerable.ToArray[Countries] (IEnumerable`1 source)
[0x00000] 
  at Linq1.MainClass.LinqToPostgres () [0x00012] in
/home/evgenyp/Projects/Linq1/Main.cs:41 
  at Linq1.MainClass.Main (System.String[] args) [0x00000] in
/home/evgenyp/Projects/Linq1/Main.cs:1 

What version of the product are you using? On what operating system?

DbLinq from SVN revision 1234, Mono 2.4.3.2, Ubuntu 9.04 x64, PostgreSQL 8.3.1.

Original issue reported on code.google.com by emp....@gmail.com on 12 Oct 2009 at 4:30

Attachments:

@GoogleCodeExporter
Copy link
Author

Workaround: manually edit the generated file and globally replace "private" with
"public".

Original comment by emp....@gmail.com on 12 Oct 2009 at 4:38

@GoogleCodeExporter
Copy link
Author

This problem only occurs on Mono - when I run the same code on Microsoft .NET 
3.5 SP1
it works!

Original comment by emp....@gmail.com on 19 Oct 2009 at 1:10

@GoogleCodeExporter
Copy link
Author

A fix, for anyone with time (ha!), would be to take r1217 and do the same thing 
for 
DbMetal.  That was another case of FieldAccessException under Mono but not .NET 
that 
was easily worked around...

Original comment by jonmpr...@gmail.com on 20 Oct 2009 at 6:57

@GoogleCodeExporter
Copy link
Author

I believe that this is actually a Mono 2.4 bug that was fixed in Mono 2.6; see: 

  http://groups.google.com/group/dblinq/msg/712ad4d2d47f965c

Specifically, see the table where Mono 2.4.2.3 has 326 failures, while 2.6 has 
6.  
Most of those are due to the FieldAccessException being reported here.

The fix is to upgrade to Mono 2.6.

Original comment by jonmpr...@gmail.com on 21 Jan 2010 at 10:02

  • Changed state: WontFix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant