473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

[C#] Convert from string to bytes !

153 100+
Why is the code not working ??
Expand|Select|Wrap|Line Numbers
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.  
  6.             Version v = new Version("2.0.0.0");
  7.             AssemblyName asmname = new AssemblyName();
  8.             asmname.Name = "System.Windows.Forms";
  9.             asmname.Version = v;
  10.             asmname.CultureInfo = new System.Globalization.CultureInfo("");
  11.             asmname.SetPublicKeyToken(System.Text.Encoding.UTF32.GetBytes("b77a5c561934e089"));
  12.  
  13.             Assembly asm = Assembly.Load(asmname);
  14.  
  15.  
  16.  
  17.             foreach (Type t in asm.GetTypes())
  18.             {
  19.                 Console.WriteLine("******  SHOWING DATA FOR " + t.FullName.ToUpper() + " ******\n");
  20.                 Program.ShowStatics(t);
  21.                 Program.ShowProperties(t);
  22.                 Program.ShowMethods(t);
  23.                 Program.ShowFields(t);
  24.             }
  25.  
  26.  
  27.             Console.ReadKey();
  28.         }
  29.  
  30.         static void ShowStatics(Type t)
  31.         {
  32.             Console.WriteLine("IsAbstract? {0}",t.IsAbstract);
  33.             Console.WriteLine("IsNested? {0}", t.IsNested);
  34.             Console.WriteLine("FullName? {0}", t.FullName);
  35.             Console.WriteLine("BaseType? {0}", t.BaseType);
  36.  
  37.         }
  38.         static void ShowMethods(Type t)
  39.         {
  40.             Console.WriteLine("\n*********** METHODS ***********");
  41.             MethodInfo[] methods = t.GetMethods();
  42.             foreach (MemberInfo method in methods)
  43.                 Console.WriteLine(method.Name);
  44.         }
  45.  
  46.         static void ShowProperties(Type t)
  47.         {
  48.             Console.WriteLine("\n*********** PROPERTIES ***********");
  49.             PropertyInfo[] properties = t.GetProperties();
  50.             foreach (PropertyInfo property in properties)
  51.                 Console.WriteLine(property.GetType() + " " + property.Name);
  52.         }
  53.  
  54.         static void ShowFields(Type t)
  55.         {
  56.             Console.WriteLine("\n*********** FIELDS ***********");
  57.             FieldInfo[] fields = t.GetFields();
  58.             foreach (FieldInfo field in fields)
  59.                 Console.WriteLine(field.GetType() + " " + field.Name);
  60.         }
  61.     }
Throwing this exception.
Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=62373761356335363139333465303839' or one of its dependencies. The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)

The public key token is not converting properly.
Oct 9 '08 #1
3 2867
Teme64
10
The hexadecimal string "b77a5c561934e089" (="b7 7a 5c 56 19 34 e0 89") has to be converted to eight bytes. Encoding.GetBytes() converts characters to bytes so you'll get 16 bytes.

Teme64 @ windevblog.blogspot.com
Oct 9 '08 #2
akshaycjoshi
153 100+
so how to solve this problem ?
Oct 9 '08 #3
Plater
7,872 Expert 4TB
How about:
Expand|Select|Wrap|Line Numbers
  1. byte[] bts = new byte[] 
  2. {
  3.     0xb7
  4.     0x7a
  5.     0x5c
  6.     0x56
  7.     0x19
  8.     0x34
  9.     0xe0
  10.     0x89
  11. }; 
  12.  
Although I really don't understand what you are doing
Oct 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.