Code Monkey home page Code Monkey logo

Comments (10)

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024 1

@Xuejiao-Shi
I fixed the problem by writing AGConnectApp.Create code at start of the application and use DefaultInstance.

Now am able to send notifications from my C# project.

Thanks for your valuable time and help.

from hms-push-serverdemo-csharp.

Xuejiao-Shi avatar Xuejiao-Shi commented on June 12, 2024

This issue may be caused by repeated creation of AGConnectApp.
similar question for you reference, but it's in Chinese, you can translate it:https://developer.huawei.com/consumer/cn/forum/topic/0201691801128470750?fid=18

from hms-push-serverdemo-csharp.

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024

But am creating AGConnectApp to access my account,

Please check below image.
123 (1)

from hms-push-serverdemo-csharp.

Xuejiao-Shi avatar Xuejiao-Shi commented on June 12, 2024

Can I confirm what changes you made in the project after you downloaded the demo?

from hms-push-serverdemo-csharp.

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024

I have Just added AGConnectAdmin SDK to my solution and added AGConnectAdmin Reference.

And try to send notification from my project using above method.
234

from hms-push-serverdemo-csharp.

Xuejiao-Shi avatar Xuejiao-Shi commented on June 12, 2024

This error may be caused by the repeated creation of AGConnectApp.
image

This is the code for throwing an exception because the AGConnectApp already exists. You may have created AGConnectApp in other places besides the code in the screenshot which you provided. You can search for the create keyword to locate the fault.

from hms-push-serverdemo-csharp.

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024

@Xuejiao-Shi
Am sure, am creating AGConnectApp only at one place. That is inside SendTestMessage().

If possible, can you test it from your end with below code please.

`
public async Task SendTestMessage()

    {

        var response = "";

        try

        {

           

            var ag = AGConnectApp.Create(new AppOptions()

            {

                ClientId = "",

                ClientSecret = ""

            });

            var msg = AGConnectMessaging.GetMessaging(ag);



            await msg.SendAsync(new Message()

            {



                Notification = new Notification()

                {

                    Title = "Test Message",

                    Body = "Detail Message",

                },

                Android = new AndroidConfig()

                {

                    Notification = new AndroidNotification()

                    {

                        Title = "Notification from .NET",

                        Body = "Hello world!",

                        ClickAction = ClickAction.OpenApp()

                    }

                },

                Token = new List<string>() { "" }

            });



           



           

        } catch (Exception ex)

        {

            response = ex.Message.ToString();

        }



       

        

        return response;

    }

`

from hms-push-serverdemo-csharp.

Xuejiao-Shi avatar Xuejiao-Shi commented on June 12, 2024

Can you delete the code for creating AGConnectApp and check whether the error persists?

from hms-push-serverdemo-csharp.

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024

Am getting Object reference not set to an instance of the object exception when used below code.

`await AGConnectMessaging.DefaultInstance.SendAsync(new Message()

             {



                 Notification = new Notification()

                 {

                     Title = "Test Message",

                     Body = "Detail Message",

                 },

                 Android = new AndroidConfig()

                 {

                     Notification = new AndroidNotification()

                     {

                         Title = "Notification from .NET",

                         Body = "Hello world!",

                         ClickAction = ClickAction.OpenApp()

                     }

                 },

                 Token = new List<string>() { "IQAAAACy0uRmAAAvsZe3QA42M8KS-3Dg6Dyqubcc8cTUIj-PW7tV0z82aiuXXNoNR_n_XV9HZ0BUa9VtkAi-OUNGxXN_rLYNbhgad5mgfBvdirxssQ" }

             });`

from hms-push-serverdemo-csharp.

Ghousepasha-ios avatar Ghousepasha-ios commented on June 12, 2024

@Xuejiao-Shi
Am using above code in ASP.net Webapi project,

Do i need to initialise below code some where else and access ag ?

var ag = AGConnectApp.Create(new AppOptions()

            {

                ClientId = "",

                ClientSecret = ""

            });

from hms-push-serverdemo-csharp.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.