Search code examples
c#xamarinportable-class-libraryweb-reference

"System.Runtime.Serialization'. Are you missing an assembly reference?" after adding web reference


I have an iOS/Android Xamarin project that share a PCL project.

I have added a web reference to the PCL via ASMX as per Xamarin's Tutorial. The tutorial doesn't say how to get to the "Add Web Reference" window, but we found it by right-clicking our PCL project and going to Add->Web Reference.

On adding the web reference I get a roughly 500 line Reference.cs file that is added to the PCL.

However, on compilation, either iOS or Android, I am given several of these errors:

Reference.cs(74,74): Error CS0234: The type or namespace name IExtensibleDataObject' does not exist in the namespaceSystem.Runtime.Serialization'. Are you missing an assembly reference? (CS0234) (MyProject)

It is clear that I need to add the System.Runtime.Serialization assembly reference. However I cannot figure out how to do this and I have spent hours looking for documentation or any relevant solution. Most posts questions appear tangental at best.

This forum post references this issue, but give no solution other than it was supposedly “fixed” three years ago.

Now the aforementioned tutorial references an "Add References…" dialog box for adding the System.Web.Services.dll if you use "Add files" to add the proxy. However, I cannot find this dialog anywhere in the IDE.

I did find "Edit References" when right-clicking on references. This produced a window with these tabs:

enter image description here

Guessing that the assembly needs to be added here I search for it, but find nothing. Apparently there is no way to add assemblies that are packaged with the IDE, you're expected to "just know" where to find them. Searching for documentation proves fruitless.

Via one of the sample project, I was able to locate the .dll file at /Library/Frameworks/Mono.framework/Versions/4.4.2/lib/mono/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile78/System.Runtime.Serialization.dll and manually add it via the .NET Assembly tab.

A colleague tried adding the reference via NuGet as well.

Unfortunately the compile errors remain after attempting either approach.

Also, of note, it appears that the ToDoASMX example project nor the folder containing the System.Runtime.Serialization.dll have any references to the System.Web.Services.dll that the tutorial mentions.


Solution

  • I believe these docs are referring to using them in Xamarin.iOS and Xamarin.Android(At least for the .asmx docs). You can get to System.Runtime.Serializationvia right clicking References in your Xamarin.iOS/ Xamarin.Android project, Going to Edit References, then going to the All tab which it should be listed under the BCL (Base Class LIbrary). You may need to go the route of using an Interface based pattern within your PCL to call the respective native web service instead. You could also try wrapping your .asmx into a REST service and using HttpClient as well.

    Seeing this sample project(https://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoASMX/) shows the Interface based pattern described above using ISoapService in the PCL and implementing in the native projects. You will see each project (Droid/iOS) have the Web Reference in them. The PCL is purely invoking the code.

    It's more of a limitation of using .asmx given the framework built around them. Using WCF or REST have better options for consuming directly from a PCL. However note that PCLs are going to be replaced by NetStandard library flavor.