user119698: I'm trying to build a transaction using Nbitcoin. When I run this line there is an error parsing the address. It runs fine with segwit addresses starting with a 1, but not native segwit.
Using System;
Using System.Text;
Using NBitcoin;

static void Main(string[] args) {

    var wallet = new BitcoinPubKeyAddress("bc1q....", Network.Main); //throws error
}

Error: System.FormatException: 'Invalid base58 data'
Is there a way to use native segwit with Nbitcoin? Thanks

user-1: 
It runs fine with segwit addresses starting with a 1, but not native segwit.

Prefix 1 is used by legacy addresses. You can check the other prefixes used here: https://en.bitcoin.it/wiki/List_of_address_prefixes

Is there a way to use native segwit with Nbitcoin?

Replace BitcoinPubKeyAddress with BitcoinWitPubKeyAddress in your code for using native segwit addresses

119698: <p>I'm trying to build a transaction using Nbitcoin. When I run this line there is an error parsing the address. It runs fine with segwit addresses starting with a 1, but not native segwit.</p>
<pre><code>Using System;
Using System.Text;
Using NBitcoin;

static void Main(string[] args) {

    var wallet = new BitcoinPubKeyAddress(&quot;bc1q....&quot;, Network.Main); //throws error
}
</code></pre>
<p><strong>Error:</strong> System.FormatException: 'Invalid base58 data'</p>
<p>Is there a way to use native segwit with Nbitcoin? Thanks</p>
 -1: <blockquote>
<p>It runs fine with segwit addresses starting with a 1, but not native segwit.</p>
</blockquote>
<p>Prefix <code>1</code> is used by legacy addresses. You can check the other prefixes used here: <a href="https://en.bitcoin.it/wiki/List_of_address_prefixes" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/List_of_address_prefixes</a></p>
<blockquote>
<p>Is there a way to use native segwit with Nbitcoin?</p>
</blockquote>
<p>Replace <code>BitcoinPubKeyAddress</code> with <code>BitcoinWitPubKeyAddress</code> in your code for using native segwit addresses</p>
