Jar Binding Issue (The type or namespace name 'IO' does not exist in the namespace...)

chad_cumberlandchad_cumberland Member ✭✭
edited March 20 in Xamarin.Android

Hello

I am trying to create a jar binding library and am having an issue with some of the auto generated code in an interface.

For example:

The java code looks like this:

package com.xxx.xxx;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Set;

/**
 * Provides method which permits to export and import data, retrieve data
 */
public interface IDataFile {

    /**
     * <p>Add authority if the list of authorities doesn't contained already the authority given in parameter.
     * Add both key and value to the authority given in parameter.</p>
     * @param authority the authority to add to the list
     * @param key       the key we want to add to the given authority
     * @param value     the value we want to add to the given authority
     */
    public void addKeyValue(String authority, String key, String value);

    /**
     * <p>Export data into XML. As flush doesn't do anything on FileOutputStream use filedescriptor to sync </p>
     * @param  stream the output stream to transform into xml
     * @return        True if the exporting of the data has succeeded. False otherwise. 
     */
    public boolean exportData(OutputStream stream);

    /**
     * Read and parse data from input stream given in parameter.
     * 
     * @param  stream the input stream 
     * @return        <p>True if the XML configuration and the XML parsing has been successful. 
     *                False if there are XML configuration exception, XML reading exception or 
     *                XML IO reading exception.</p>
     */
    public boolean importData(InputStream stream);

    /**
     * Retrieve a data map from the authority.
     * @param  authority the authority
     * @return           a data map containing a list of authorities
     */
    public Map<String, String> getData(String authority);

    /**
     * Retrieve a set of authorities
     * @return a set of authorities.
     */
    public Set<String> getAuthorities();
}

the api.xml contains the following entry:

<interface abstract="true" deprecated="not deprecated" final="false" name="IDataFile" static="false" visibility="public">
  <method abstract="true" deprecated="not deprecated" final="false" name="addKeyValue" native="false" return="void" static="false" synchronized="false" visibility="public">
    <parameter name="p0" type="java.lang.String"></parameter>
    <parameter name="p1" type="java.lang.String"></parameter>
    <parameter name="p2" type="java.lang.String"></parameter>
  </method>
  <method abstract="true" deprecated="not deprecated" final="false" name="exportData" native="false" return="boolean" static="false" synchronized="false" visibility="public">
    <parameter name="p0" type="java.io.OutputStream"></parameter>
  </method>
  <method abstract="true" deprecated="not deprecated" final="false" name="getAuthorities" native="false" return="java.util.Set&lt;java.lang.String&gt;" static="false" synchronized="false" visibility="public">
  </method>
  <method abstract="true" deprecated="not deprecated" final="false" name="getData" native="false" return="java.util.Map&lt;java.lang.String, java.lang.String&gt;" static="false" synchronized="false" visibility="public">
    <parameter name="p0" type="java.lang.String"></parameter>
  </method>
  <method abstract="true" deprecated="not deprecated" final="false" name="importData" native="false" return="boolean" static="false" synchronized="false" visibility="public">
    <parameter name="p0" type="java.io.InputStream"></parameter>
  </method>
</interface>

So all looks good but I get the following error:

The type or namespace name 'IO' does not exist in the namespace...

pointing to the following code in the C#:

static bool n_ExportData_Ljava_io_OutputStream_ (IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
{
    global::Com.Parkeon.Data.IDataFile __this = global::Java.Lang.Object.GetObject<global::Com.Parkeon.Data.IDataFile> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
    System.IO.Stream p0 = global::Android.Runtime.OutputStreamInvoker.FromJniHandle (native_p0, JniHandleOwnership.DoNotTransfer);
    bool __ret = __this.ExportData (p0);
    return __ret;
}

The error is regarding the System.IO.Stream. It goes away if I manually add global:: in front so that the line reads

global::System.IO.Stream p0 = global::Android.Runtime.OutputStreamInvoker.FromJniHandle (native_p0, JniHandleOwnership.DoNotTransfer);

But I have 30 of these that would need to be fix each rebuild.

How do I fix this issue please

Regards

Chad

Best Answer

  • Accepted Answer

    It turns out that an imported namespace ended in System and clashed with the .NET System namespace. Renaming the imported namespace fixed the issue.

Answers

Sign In or Register to comment.