[SOLVED] C# namespace name 'Models' does not exist in the namespace 'Moralis'

Hi, I’m trying the following tutorial

But I’m receiving an error
" namespace name ‘Models’ does not exist in the namespace ‘Moralis’ (are you missing an assembly reference?)"

I have added the Moralis library to the application

using Moralis;
using Moralis.Web3Api.Models;

namespace ConsoleDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.Write("Usage: ConsoleDemo.exe ADDRESS CLIENT_ID");
                return;
            }

            string address = "########";
            ChainList chainId = ChainList.eth;

            // Setup Moralis Client
            **MoralisClient.ConnectionData = new Moralis.Models.ServerConnectionData()**
            {
                ApiKey = "#####"
            };

            Task.Run(async () =>
            {
                await DisplayCryptoData(address, chainId);
            }).Wait();

        }

        internal static async Task DisplayCryptoData(string address, ChainList chainId)
        {
            try
            {
                Console.WriteLine($"For address: {address}...\n");

                // Load native balance for address
                NativeBalance bal = await MoralisClient.Web3Api.Account.GetNativeBalance(address, chainId);

                double nativeBal = 0;

                double.TryParse(bal.Balance, out nativeBal);

                Console.WriteLine($"Your native balance is {bal.NativeTokenBalance}");

                // Load ERC20 Token List for address
                List<Erc20TokenBalance> erc20Balnaces = await MoralisClient.Web3Api.Account.GetTokenBalances(address, chainId);

                Console.WriteLine("\n\nYour ERC 20 Tokens:");

                if (erc20Balnaces != null && erc20Balnaces.Count > 0)
                {
                    // Print out each token with symbol and balance.
                    foreach (Erc20TokenBalance tb in erc20Balnaces)
                    {
                        Console.WriteLine($"\t{tb.Symbol} - {tb.Name}: {tb.NativeTokenBalance}");
                    }
                }
                else
                {
                    Console.WriteLine("\tNone");
                }

                // Load first 10 NFTs for the address
                NftOwnerCollection nfts = await MoralisClient.Web3Api.Account.GetNFTs(address, (ChainList)chainId, "", null, 10);

                Console.WriteLine("\n\nYour NFTs:");

                if (nfts != null && nfts.Result.Count > 0)
                {
                    // Print out each token with symbol and balance.
                    foreach (NftOwner nft in nfts.Result)
                    {
                        Console.WriteLine($"\t{nft.Name}: {nft.Amount}\n\tMetaData: {nft.Metadata}\n\n");
                    }
                }
                else
                {
                    Console.WriteLine("\tNone");
                }

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
        }
    }
}

it looks like the error could be from here

here is imported as Moralis.Web3Api.Models

I don’t know how it should be used or if it should work as it is

Yes that’s where it’s breaking, it doesn’t seem to have ConnectionData or Models definition within the MoralisClient interface

// Setup Moralis Client
MoralisClient.ConnectionData = new Moralis.Models.ServerConnectionData()
{
ApiKey = “”
};

Hi, I’m still waiting on a reply to my ticket/issue.

Thanks,

Tom


Hey @brucey54,

Can we know which version of the C# SDK are you using at the moment? :raised_hands:

So we can assist accordingly, thanks!

Hi YosephKS, I’m using C# SDK Moralis 1.0.4.6

That’s the latest version.

Thanks,
Tom

Hey @brucey54,

If your version is 1.0.4.6, it might not suit the tutorial that you have in here :raised_hands:

As you see that this tutorial is for C# SDK version 2.x.x

The namespace error might come from here. Let me know if you have any other questions

2 Likes

Thanks YosephKS, I can’t believe I never spotted that :wink:

1 Like

Great!

Well if you have any other issue, feel free to create a new post :grinning_face_with_smiling_eyes: as we will be available 24/7 to help you out.

Hope you have a great day and I’ll be closing this post for now~