# The start method for OneAgent is not valid in MAUI

**URL:** <https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149>\
**Category:** Open Q&A\
**Tags:** android, mobile-monitoring\
**Created:** [December 12, 2023, 10:03am UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149 "2023-12-12T10:03:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KenXu](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@KenXu](https://community.dynatrace.com/u/KenXu)\
**Post date:** [December 12, 2023, 10:03am UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149/1 "2023-12-12T10:03:53Z")

</div>

I’m trying to migrate my old Xamarin Form App to .Net MAUI application.

According to the document for .Net MAUI, I installed&nbsp;[**Dynatrace.OneAgent.MAUI**](https://www.nuget.org/packages/Dynatrace.OneAgent.MAUI)&nbsp;package, add the config file into my project, and input the code into App.xaml.cs file after “InitializeComponent();”

```auto
using Dynatrace.MAUI;<br>namespace MauiApp2<br>{<br> public partial class App : Application<br> {<br> public App()<br> {<br> InitializeComponent();<br> <font size="4" color="#FF0000">Agent.Instance.Start();</font><br> MainPage = new AppShell();<br> }<br> }<br>Agent.Instance.Start();

```

then I rebuild my porject, and I got following error:

```auto
<font size="3">Error CS0103 The name 'Agent' does not exist in the current context </font>

```

If I change the code to:

```auto
<font size="4">Dynatrace.MAUI.Agent.Instance.Start();</font>

```

the error will be:

```auto
<font size="4" color="#000000">Error CS0234 The type or namespace name 'Agent' does not exist in the namespace 'Dynatrace.MAUI' (are you missing an assembly reference?) </font>

```

Spoiler

Platform : .Net MAUI&nbsp;  
Target platform: Android

Framework : .NET Framework 8.0

NuGet Package :&nbsp;Dynatrace.OneAgent.MAUI - V1.279.1

IDE : Visual Studio Community 2022 (64-bit) - Version 17.8.3

I got the same problem when I create a new .Net MAUI App

---

<div class="post-metadata">

**Author:** ![nicholas\_mcwher](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/nicholas_mcwher/32/6822_2.png) [@nicholas\_mcwher](https://community.dynatrace.com/u/nicholas_mcwher)\
**Post date:** [December 12, 2023, 4:11pm UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149/2 "2023-12-12T16:11:25Z")

</div>

Hi there!

Thanks for reaching out. Based on your tests with a new MAUI app using .NET 8, I was able to add our MAUI package and use the same steps that you did to build and start the app with the agent loading properly when the app starts. How are you installing the package? Are you building via Visual Studio or using msbuild? Windows or Mac?

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![KenXu](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@KenXu](https://community.dynatrace.com/u/KenXu)\
**Post date:** [December 13, 2023, 7:26am UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149/3 "2023-12-13T07:26:54Z")

</div>

I install the package from the NuGet package management,&nbsp;building via Visual Studio on&nbsp; Windows.

I have one question, where are you insert the start code?&nbsp;App.xaml.cs or other file?

 ![KenXu_0-1702450524460.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/143f7a9ba8431b980a965148c0da2504358c2911.png)

I got the error when input&nbsp;Agent.Instance.Start(); in App.xaml.cs, but it works fine when I input the in MainApplication.cs file, as the place to input the code has not been mentioned in the document.

I just upload a video in google drive

[https://drive.google.com/file/d/1BzPTZB59ixcubyy4g23IUC88Upmrs5Fc/view?usp=sharing](https://drive.google.com/file/d/1BzPTZB59ixcubyy4g23IUC88Upmrs5Fc/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![nicholas\_mcwher](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/nicholas_mcwher/32/6822_2.png) [@nicholas\_mcwher](https://community.dynatrace.com/u/nicholas_mcwher)\
**Post date:** [December 13, 2023, 7:29pm UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149/4 "2023-12-13T19:29:45Z")

</div>

Thanks very much for the video of the issue. It made things a lot easier to understand!

I was originally testing on a Mac so the situation was a little different on my end. I installed Visual Studio on a windows VM so that I could get a better understanding of the issue you are facing. It looks like you have “Windows” selected as the platform to test with (or context I suppose) which is not supported with our NuGet package. To get this to work properly, you have to click the drop down menu near the top left (see images) and select android. This should resolve the issue you are facing.

If you run into any problems with the instructions that I provided, please let me know!

Thanks,

Nick

 ![Screenshot 2023-12-13 at 2.22.51 PM.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/5/4/5451a019a787cdec0f2dd4d6e81f5fa2b038036b.jpeg)  
 ![Screenshot 2023-12-13 at 2.21.46 PM.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/2/20c27cd72ab53cf824c8640f04d0bc8fffbcaab5.jpeg)

---

<div class="post-metadata">

**Author:** ![KenXu](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@KenXu](https://community.dynatrace.com/u/KenXu)\
**Post date:** [December 14, 2023, 10:03am UTC](https://community.dynatrace.com/t/the-start-method-for-oneagent-is-not-valid-in-maui/43149/5 "2023-12-14T10:03:10Z")

</div>

Thanks&nbsp;[nicholas\_mcwher](https://community.dynatrace.com/user/38469)&nbsp;&nbsp;it works now, what I did is

1: un-check windows platform

2: remove&nbsp;net8.0-maccatalyst from the&nbsp;TargetFrameworks in .csproj file (as there is no maccatalyst options in project propery page)

```auto
<font size="3"><TargetFrameworks>net8.0-android</TargetFrameworks></font>

```

Thanks,

Ken Xu
