Mono.Cecil type cast error on build server

11 posts, 0 answers
  1. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 06 Nov 2015 Link to this post

    Just finished converting my rlinq files to fluent api with the nuget packages and everything works fine on my machine but on te build server I am getting this error:

     OpenAccess Enhancer error 0: Unable to cast object of type 'Mono.Cecil.TypeReference' to type 'Mono.Cecil.TypeDefinition'.

     Anybody have any clue where to begin to look to fix this?

    The error just points to the dll project with location (-1,-1) 

  2. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 06 Nov 2015 Link to this post

    So I did some more troubleshooting:

    I installed Visual Studio Community Version 2015 on the build server.  I opened the same code that is being built with MSBuild on the server.  I tried compiling and it worked fine, no errors at all.  

    I went to an admin command prompt and ran msbuild from C:\windows\microsoft.net\Framework64\v4.0.30319 passing it the same parameters the build server uses and it failed with the same errors:

    "[Full Path To My Project].vbproj" (default target) (1) ->
    (OpenAccessEnhancer target) -> 
      [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0: Unable to cast object of type 'Mono.Cecil.TypeReference' to type 'Mono.Cecil.TypeDefinition'. [[Full Path To My Project].vbproj]
      [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0: System.InvalidCastException: Unable to cast object of type 'Mono.Cecil.TypeReference' to type 'Mono.Cecil.TypeDefinition'. [[Full Path To My Project].vbproj]
    [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.CecilPersistentBuilder.Intercept(MethodDefinition method) [[Full Path To My Project].vbproj]
    [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.CecilEnhancer.InterceptPersistentFieldAccess(TypeDefinition typedef) [[Full Path To My Project].vbproj]
    [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.CecilEnhancer.InterceptPersistentFieldAccess() [[Full Path To My Project].vbproj]
    [Full Path To My obj\Test dll].dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.CecilEnhancer.ProcessAssembly() [[Full Path To My Project].vbproj] 

    Also tired to the Framework directory alone and had the same results.

  3. DevCraft banner
  4. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 06 Nov 2015 Link to this post

    So I was able to convert another project to use the Fluent Nuget assemblies and build on that same server just fine.  That would mean that something in my code is causing the problem and only when it is built using MSBuild.  Is there any way to get more debugging information about this casting error? 
  5. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 09 Nov 2015 Link to this post

    So turns out my issue was a missing assembly.  My solution has multiple projects, on class library and one web project.  I only installed the Fluent and Core nuget packages in the class library project.  This would build fine, run, and debug no problem inside ​Visual ​Studio, but would not work from MSBuild.  I added just the Core nuget to my web project and that made it able to build from MSBuild.    I had all the telerik assemblies set to copy local but the "Runtime" one never made it to the bin folder of my web project, I guess msbuild did some optimizations and decided it was not needed since nothing was referencing it in the project.  
  6. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 09 Nov 2015 Link to this post

    Oops, so I spoke too soon, seems that did not fix my MSBuild issue, still having the problem, can anyone point me to anything that can help, the error message is not descriptive enough to figure out which piece of my code is the problem ;(
  7. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 10 Nov 2015 Link to this post

    Hi Frank,

    We have fixed this issue already and we are working on releasing a new version. Am I right that this is VB?

    Regards,
    Jan Blessenohl
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  8. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 10 Nov 2015 in reply to Jan Blessenohl Link to this post

    Hi Jan,

     Yes, you are correct I am using VB.Net.  But just to make sure, here is what I have figured out so far.

     Using a .net decompiler I was able to debug the error down and figure out the methods that were failing and one by one fixed them.  The first ones were due to my copy and pasting of code in the context class that was generated by the old designer tool.  I had one assembly with multiple rlinq files.  Most of the project uses MSSQL but there are a few pieces of code that use MySQL and PostGres so my assembly had multiple rlinq files.  I follow​ed the blog post on how to convert them from the designer tool and to the new fluent + nuget style.  The MySQL and PostGres ones were small and simple but the MSSQL was quite large so to save time I reused code, some of which pointed to stored procedures that used return values.  The generated code used ByRef parameters and that seemed to make the Cecil library in the enhancer code fail.  

    I fixed all of those and thought I was ok but then the Cecil library started to complain about methods that the did not use the context class at all.  I have some methods that use plain ADO and for what ever reason, the enhancer is trying to alter them?  Best I could tell is that since these methods are in a class with other methods that do use a context class, they are subject to enhancement.  If I comment out the body of these methods, I can get the enhancer to complete but when the code actually runs I get all sorts of errors about "Type is enhanced and registered, but not available from the database class meta data. This can be caused by a wrong connection id or configuration".  

    At this point my upgrade has been a disaster :(  If you have a fix please let me know as I can't get any data access to work reliably now.

     

    Thanks,

    Frank

     

  9. Frank
    Frank avatar
    8 posts
    Member since:
    Jan 2013

    Posted 11 Nov 2015 in reply to Frank Link to this post

    Hi Jan

     So I have it all working now, in the end I had two main issues, one my fault and the other the enhancers.  My error was due to copy and pasting during the conversion of using rlinq files to fluent + nuget.  I followed the blog post that describes how to do the conversion and somehow missed the copying on the generated context classes, instead I used the versions from before I had in source control.  This caused the "Type is enhanced and registered, but not available from the database class meta data. This can be caused by a wrong connection id or configuration" error since these were trying to get the metadata from embedded rlinq files instead of the newly created fluent ones.  I guess I never really had to know how OpenAccess worked before when using the designer, it was just point and click, but now with the fluent code first method I have to write more code, like the context and mapping classes.  A single mistake in there can lead to days of down time.  

     As for the enhancer, I could not get it to stop trying to enhance methods that had nothing to do with OpenAccess so I just split all my OpenAccess code out of that assembly.  Instead of one business class library I now have one business and one database which contains only the OpenAccess code.  

     Thanks,

    Frank

  10. Sébastien
    Sébastien avatar
    4 posts
    Member since:
    Mar 2015

    Posted 18 Dec 2015 in reply to Jan Blessenohl Link to this post

    Do you know the date of this next release?

    Because:

    *Last release fix visual studio 2015 integration

    *BUT last release introduce bug with mono cecil and vb.net project.

    So, i can't move to visual studio 2015 until you fix this error

    Thanks

  11. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 23 Dec 2015 Link to this post

    Hello Sebastien,

    We have just released the next version of Telerik Data Access (2015 Q3 SP1, version 2015.3.1221.1).
    You can get the latest NuGet packages from NuGet.org and check the release notes.
    We have shipped a fix that we believe resolve the issue with VB.Net Enhancing and should enable you to use Visual Studio 2015 for your Telerik Data Access based projects.

    Happy holidays,
    Viktor Zhivkov
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  12. Sébastien
    Sébastien avatar
    4 posts
    Member since:
    Mar 2015

    Posted 23 Dec 2015 in reply to Viktor Zhivkov Link to this post

    Hello,

    Thanks a lot for this fix.

    My problem is solved.

    Merry christmas

Back to Top
DevCraft banner