Did you face an ambiguous class/entity reference in your WCF RIA Service or Silverlight project? Then this post might help you to resolve the error. - Article authored by Kunal Chowdhury on .
Ambiguity is the ability to express more than one interpretation in normal way. This can happen in any manner; in our code too. If you are working on WCF RIA Services in Silverlight, you might encounter this issue too with class references.
Today in this blog post, I will share you a small trick by which you will be able to fix this error in your Silverlight project. Continue reading to further discussion.
If you have two classes or entity having same name but two different namespace inside your RIA Service web project, you might face this issue in your generated code. In this case, it will throw a build error saying “Ambiguous Reference between the two classes”. The reason behind this is very simple. The compiler can’t identify the proper class that it needs to use. In normal scenario, you might try to put a fully qualify class name in all the places but there you will find no luck.
So, what’s the issue and how can you fix this? An issue has been already reported in Microsoft connect and a solution from Microsoft. This situation arises when the application declares a type with the same (short) name as one of our framework types. It was deemed too expensive for the code generator to walk all referenced assemblies and all using statements to detect conflicts in short type names.
If you experienced similar issue in your Silverlight project, just follow the below mentioned steps to resolve the error and continue working with RIA Services in Silverlight:
This will fix the issue for the current project that you modified. If you unloaded the project from Visual Studio IDE, reload it back. Now you will be able to clean and rebuild the whole solution without any issues.
If you are working on multiple projects in same machine environment, you don’t have to do it for individual projects. You can directly set the environment variable %RiaClientUserFullTypeNames% to the string value "true". Now this will allow the compiler to fully qualify all the type names and you will not face the above ambiguity issue in the Generated Code file of your RIA Services. I hope, the information was helpful for you and resolved your problem related to ambiguity.
Solution Architect & Former Microsoft MVP
Kunal Chowdhury is an enterprise solution architect and former multi-year Microsoft MVP. He is the author of three technical books: Windows Presentation Foundation Development Cookbook, Mastering Visual Studio 2017, and the Mastering Visual Studio 2019.
He publishes technical and non-technical articles on Kunal-Chowdhury.com.