Results 1 to 6 of 6

Thread: Value of type string cannot be converted and property is readonly

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    3

    Post Value of type string cannot be converted and property is readonly

    Already asked this question in stackoverflow and bitcoin stackexchange forums but nothing helpful. So the problem is that I want to use few values entered by user at run time in textboxes but I cannot assign them directly being string to variables that are part of a class and read only. It was easier to do the opposite which is convert one of these values to string and display as label etc.

    Here is the code:

    Code:
    Imports NBitcoin
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim bob As New Key
            Dim alice As New Key
            Dim satoshi As New Key
            
           'bob.PubKey = TextBox1.Text
           'alice.PubKey = TextBox2.Text
           'satoshi.PubKey = TextBox3.Text
    
    
            Dim redeemScript As Script = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, {bob.PubKey, alice.PubKey, satoshi.PubKey})
    
            Label1.Text = redeemScript.Hash.GetAddress(Network.TestNet).ToString
            
    
    
        End Sub
    End Class
    Links to the other two forums where I asked the same question:

    https://stackoverflow.com/questions/...ty-is-readonly

    https://bitcoin.stackexchange.com/qu...using-nbitcoin

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Value of type string cannot be converted and property is readonly

    The public key is not an arbitrary string. It is binary data that is generated cryptographically. There is a constructor that accepts a Byte array from which the public key can be generated but it's still not a straight assignment. You need to do more research on the types you're using and Bitcoin/Blockchain as a whole I think.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    3

    Re: Value of type string cannot be converted and property is readonly

    Okay I will do more research and see if I can resolve this issue soon. I am working on a VB.NET project after few years. Do people still use VB for development or it's better to use C# or something else?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Value of type string cannot be converted and property is readonly

    Quote Originally Posted by Boboshi View Post
    Do people still use VB for development or it's better to use C# or something else?
    If you're targeting the .NET Framework and particularly Windows apps, VB can do all you need. It is still quite popular, particularly with hobbyists. That said, C# has been the preferred language for professional developers pretty much from the start and the gap has been growing since. Microsoft have officially stopped treating the two languages as equals so many new features come to C# first and VB later, if at all. For instance, there are still significant holes in the .NET Core support for VB. I think that many of those will close with the official release of .NET 5.0 but there will still be things that C# can do that VB can't or, at least, can't easily. If you want access to the latest and greatest that .NET has to offer and the greatest chance of being employed as a .NET developer, you ought to be using C# alone or, like me, as well as VB. The good news is that pretty much everything you know about .NET development from VB is applicable to C#. The syntax changes but the principles are all pretty much the same. For simple code, the only changes required may be adding a semicolon to the end of each line.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Value of type string cannot be converted and property is readonly

    It's also worth noting that a lot of examples available online, particularly for advanced topics, are likely to be available in C# only. You can generally translate them into VB if required but it's an extra effort. If you need to convert C# code examples then I would recommend Instant VB, as it is far more reliable than online converters and there's a free version that can handle snippets.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    3

    Re: Value of type string cannot be converted and property is readonly

    Thanks for answering. I think I will use VB.NET for this project but prefer C# in future.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width