Bugzilla – Bug 316154
string.ctor with encoding objunimplemented
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by michael_cohen@maxtor.com 2004-09-30 17:21:14 MST ---- Description of Problem: First, let me apologize. I'm very new to Linux and Mono, but here is the problem I'm seeing, as best as I can describe it: I have an assembly (built using .NET on windows), which I reference in a GTK# project running on Mono/Linux. During the execution of a method in that assembly, I try to create a new string in an unsafe block using an sbyte*. The offending code is probably the code I've pasted below. (I say probably, because I am still not sure how to use the debugger - again I apologize for not providing more info) This code snippet is not complete, but should give you an idea of what i'm trying to do: protected override void InitValue() { try { String s; s = ""; unsafe { s = ""; SByte[] s1 = new SByte[mLength]; for (int i = 0; i < mLength; i++) { s1[i] = (sbyte)mBuffer.Data[this.ByteOffset + i]; } fixed (sbyte* s2 = (sbyte*)&s1[0]) { s = new String(s2, 0, mLength, System.Text.Encoding.ASCII); } } this.Value = s; } catch (Exception e) { ExceptionHandler.SendErrorMessage(e); return; } } My mono version information is: mscorlib 1.0.5000 Steps to reproduce the problem: 1. I do not yet have a test app which will reproduce this, but I can work on building one, if you think this would be beneficial Actual Results: ** (<unknown>:6401): WARNING **: string.ctor with encoding obj unimplemented ** ERROR **: file string-icalls.c: line 189 (ves_icall_System_String_ctor_encoding): should not be reached aborting... Expected Results: it should create the string How often does this happen? Every Time Additional Information: ---- Additional Comments From michael_cohen@maxtor.com 2004-10-01 13:44:53 MST ---- Here's the C# code that will reproduce the problem: // project created on 10/1/2004 at 1:05 PM using System; class MainClass { public static void Main(string[] args) { String s; try { s = ""; unsafe { s = ""; SByte[] s1 = new SByte[5]{ 0x01, 0x02, 0x03, 0x04, 0x00 }; fixed (sbyte* s2 = &s1[0]) { s = new String(s2, 0, 4, System.Text.Encoding.ASCII); } } } catch (Exception e) { Console.WriteLine(e.ToString()); return; } Console.WriteLine("Hello World!\n"); Console.WriteLine(s); } } ---- Additional Comments From miguel@ximian.com 2004-10-02 17:25:14 MST ---- Ben, can you look at this issue? ---- Additional Comments From bmaurer@users.sf.net 2004-10-02 17:51:13 MST ---- Cleaner test: using System; using System.Text; unsafe class MainClass { static void Main () { sbyte [] s1 = new sbyte [] { 0x01, 0x02, 0x03, 0x04, 0x00 }; fixed (sbyte* s2 = s1) { Console.WriteLine("Hello World!"); Console.WriteLine(new string (s2, 0, 4, Encoding.ASCII)); } } } ---- Additional Comments From bmaurer@users.sf.net 2004-10-02 17:51:49 MST ---- Created an attachment (id=166864) patcherooo ---- Additional Comments From bmaurer@users.sf.net 2004-10-02 17:52:15 MST ---- Would someone be so kind as to approve? ---- Additional Comments From vargaz@gmail.com 2004-10-03 10:36:41 MST ---- Approved, but the actual icall should be removed from string-icalls.c and icall.c too. ---- Additional Comments From lupus@ximian.com 2004-10-05 05:27:50 MST ---- The patch is incorrect: if it has been tested at all it may have worked by luck, because the return value from enc.GetString() happened to be left in %eax. String ctors can't be implemented that way, because they are variable-sized objects. Michael: you should use the Encoding API directly to work around the issue until we fix it: it's going to be faster for your test case anyway. ---- Additional Comments From bmaurer@users.sf.net 2004-10-05 08:14:34 MST ---- *wow* am an idiot. Yeah, i guess it must be unmanaged. Back to the drawing board. Sorry about that. ---- Additional Comments From bmaurer@users.sf.net 2004-10-05 08:15:21 MST ---- Note to self: next time test with a string that will be visible on the command line ;-). ---- Additional Comments From vargaz@gmail.com 2004-11-01 07:56:21 MST ---- Fixed in CVS. Imported an attachment (id=166864) Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>SuSE 9.1</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".