'System.Byte[]' türündeki nesne 'System.String' türüne atılamadı.'

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üye
Katılım
10 Mar 2018
Mesajlar
36
Tepki puanı
1
Yaş
26
8 HİZMET YILI
Merhaba benim şöyle bi kodum var ve şu hatayı veriyor :

System.InvalidCastException: ''System.Byte[]' türündeki nesne 'System.String' türüne atılamadı.'

Hata verilen kod :

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Hardware\\Description\\System\\CentralProcessor\\0", true); if (registryKey == null) return; memorizedIDs.Add((string)registryKey.GetValue("SystemProductName")); memorizedIDs.Add((string)registryKey.GetValue("Identifier")); memorizedIDs.Add((string)registryKey.GetValue("Previous Update Revision")); memorizedIDs.Add((string)registryKey.GetValue("ProcessorNameString")); memorizedIDs.Add((string)registryKey.GetValue("VendorIdentifier")); memorizedIDs.Add((string)registryKey.GetValue("Platform Specific Field1")); memorizedIDs.Add((string)registryKey.GetValue("Component Information")); registryKey.Close();
 
Uzman Üye
Katılım
18 Kas 2019
Mesajlar
164
Çözümler
2
Tepki puanı
13
Ödüller
3
Yaş
24
6 HİZMET YILI
hatanın tam olarak hangi satırda olduğunu söyleyebilir misin?
regedit den bir veri okursan byte türünde gelir. internetten byte to string c# diye bir arat istersen
 
Banlı Üye
Katılım
6 May 2021
Mesajlar
8
Tepki puanı
0
Ödüller
1
Yaş
26
5 HİZMET YILI
(string) yerine
C#:
.ToString();
kullanmalısın. Örnek

C#:
memorizedIDs.Add((string)registryKey.GetValue("SystemProductName"));

Yerine

memorizedIDs.Add(registryKey.GetValue("SystemProductName").ToString());

Biraz spoofer keyleri görüyorum orda o_O
 
Banlı Üye
Katılım
12 Tem 2020
Mesajlar
196
Çözümler
1
Tepki puanı
33
Ödüller
3
5 HİZMET YILI
(string) yerine
C#:
.ToString();
kullanmalısın. Örnek

C#:
memorizedIDs.Add((string)registryKey.GetValue("SystemProductName"));

Yerine

memorizedIDs.Add(registryKey.GetValue("SystemProductName").ToString());

Biraz spoofer keyleri görüyorum orda o_O
yada System.Text.Encoding.UTF8.GetString();
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst