System.IO / Java.IO Reference Ambiguity

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

System.IO / Java.IO Reference Ambiguity

Samus Arin
This post was updated on .
When a (java) OutputStreamWriter is instantiated with a (java) FileOutputStream

     Java.IO.FileOutputStream os = new Java.IO.FileOutputStream("/sdcard/app.log");
  > Java.IO.OutputStreamWriter osw = new Java.IO.OutputStreamWriter(os);

I get the following compile-time error

   cannot convert from 'Java.IO.FileOutputStream' to 'System.IO.Stream'

Even though I'm using absolute class names, it seems that the compiler is still considering "os" a (.net) System.IO.Stream ?

=============================================================
Development Environment
=============================================================
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel
Xamarin.Android   4.6.07004 (95789e18)
=============================================================

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: System.IO / Java.IO Reference Inconsistencies

Jonathan Pryor-2
On Sep 30, 2013, at 1:01 PM, Samus Arin <[hidden email]> wrote:
> When a (java) OutputStreamWriter is instantiated with a (java) FileOutputStream
...
>   cannot convert from 'Java.IO.FileOutputStream' to 'System.IO.Stream'
>
> Even though I'm using absolute class names, it seems that the compiler is still considering "os" a (.net) System.IO.Stream ?

This is (unfortunately) by design. In order to facilitate reuse of existing .NET code, we made the decision to "hide" many Java types in preference for the corresponding .NET types. In this case, we hid Java.IO.* types in preference to System.IO.* types. (In early versions, we didn't even expose many Java.IO.* types!)

Consequently, there is no OutputStreamWriter(OutputStream) constructor.

This is an unfortunate design choice, and something I'll look into fixing in a future release (by generating overloads; return types won't change).

In the meantime, if you really want to use Java.IO types, you'll need to use an intermediate Android.Runtime.OutputStreamInvoker:

        var os  = new Java.IO.FileOutputStream ("/sdcard/app.log");
        var osw = new Java.IO.OutputStreamWriter (new Android.Runtime.OutputStreamInvoker (os));

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid