0

I am building a Xamarin.Forms application. I have two libraries:

  • MyProj.ViewModels
  • MyProj.DataAccess

My DataAccess libary is accessing my Sqlite database and returning a dynamic object like so:

var calls = from customer in conn.Table<Customer>().ToList()
            join call in conn.Table<Calls>().ToList()
            on customer.Id equals call.CustomerId
            group customer by call.CallDate into grouped
            select new { Customers = grouped, CallDate = grouped.Key };

I would then like to access the properties of this dynamic object in my ViewModels library but due to dynamic objects being internal I get an exception saying:

object does not contain a definition for 'x'

I thought about adding the InternalsVisibleTo attribute:

[assembly: InternalsVisibleTo("MyProj.ViewModels")]

but this doesn't seem to work. Is it possible to use anonymous / dynamic types and the InternalsVisibleTo attribute to access dynamic objects in a different library to the one they were created in?

but this doesn't seem to work.

PS.

I have also checked whether my assembly is a strongly named assembly using this and I can confirm it isn't a strongly named assembly.

I have also checked that an Internal TestClass is visible to my MyProj.ViewModels libary which it was, so I can confirm the InternalsVisibleTo attribute works, it just doesn't work with dynamic could this be a portable class library bug?

JKennedy
  • 18,150
  • 17
  • 114
  • 198
  • 1
    Possible duplicate of [Return/consume dynamic anonymous type across assembly boundaries](http://stackoverflow.com/questions/2993200/return-consume-dynamic-anonymous-type-across-assembly-boundaries) – James Thorpe Aug 24 '16 at 11:16
  • @JamesThorpe The `ExpandoObject` doesn't seem to work with my `Sqlite` query. I am trying to use the query outlined [here](http://stackoverflow.com/a/39109727/2987066) – JKennedy Aug 24 '16 at 11:22
  • Check beyond the accepted answer on that one, there are alternatives too. However also make note of this from the accepted answer which I agree with: _"In general, anonymous types should really only be used within the same method in which they are generated. Returning an anonymous type from a method is, in general, going to cause more problems than it solves."_ – James Thorpe Aug 24 '16 at 11:25
  • Can't you create a Non Anonymous class and use? – Rohit Vipin Mathews Aug 24 '16 at 12:12
  • It is [known to work](http://www.heartysoft.com/ashic/blog/2010/5/anonymous-types-c-sharp-4-dynamic). Smells like a Mono-specific issue, its DLR not paying attention to [InternalsVisibleTo] perhaps. – Hans Passant Aug 24 '16 at 12:16
  • @HansPassant both libraries are .Net PCL libraries, could it be a .Net issue? – JKennedy Aug 24 '16 at 13:01

0 Answers0