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)
10 Answers, 1 is accepted

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.



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

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

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

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
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

Hello,
Thanks a lot for this fix.
My problem is solved.
Merry christmas