12 Dec 2023 10:03 AM - last edited on 12 Dec 2023 10:51 AM by sinisa_zubic
I'm trying to migrate my old Xamarin Form App to .Net MAUI application.
According to the document for .Net MAUI, I installed Dynatrace.OneAgent.MAUI package, add the config file into my project, and input the code into App.xaml.cs file after "InitializeComponent();"
using Dynatrace.MAUI;
namespace MauiApp2
{
public partial class App : Application
{
public App()
{
InitializeComponent();
Agent.Instance.Start();
MainPage = new AppShell();
}
}
Agent.Instance.Start();
then I rebuild my porject, and I got following error:
Error CS0103 The name 'Agent' does not exist in the current context
If I change the code to:
Dynatrace.MAUI.Agent.Instance.Start();
the error will be:
Error CS0234 The type or namespace name 'Agent' does not exist in the namespace 'Dynatrace.MAUI' (are you missing an assembly reference?)
Platform : .Net MAUI
Target platform: Android
Framework : .NET Framework 8.0
NuGet Package : 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
Solved! Go to Solution.
12 Dec 2023 04:11 PM
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
13 Dec 2023 07:26 AM
I install the package from the NuGet package management, building via Visual Studio on Windows.
I have one question, where are you insert the start code? App.xaml.cs or other file?
I got the error when input 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
13 Dec 2023 07:29 PM
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
14 Dec 2023 10:03 AM
Thanks nicholas_mcwher it works now, what I did is
1: un-check windows platform
2: remove net8.0-maccatalyst from the TargetFrameworks in .csproj file (as there is no maccatalyst options in project propery page)
<TargetFrameworks>net8.0-android</TargetFrameworks>
Thanks,
Ken Xu