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.

 

Problem Statement

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.

 

Solution

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:

    1. Inside Visual Studio IDE, unload the Silverlight client project (.csproj or .vbproj) and open it for edit. Otherwise, open the said project file directly from Windows Explorer using a Notepad.

       

    2. Add the below line to one of the property group or add to all the property groups those you can find:
      <RiaClientUseFullTypeNames>true</RiaClientUseFullTypeNames>

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.

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.