Skip to content

Commit

Permalink
Add Xamarin tvOS troubleshooting (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman authored Oct 18, 2021
1 parent ee13e55 commit 0b3e918
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 62 additions & 16 deletions src/platforms/dotnet/guides/xamarin/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,73 @@ For users on Xamarin iOS, offline caching may cause this issue.

`Failed to send cached envelope: System.MissingMethodException: Method not found: System.Text.Json.JsonDocument`

If this message displays in your debug window when capturing an event or transaction, manually edit your platform `csproj`:

1. Close your IDE.
2. Open your iOS `.csproj` with a text or xml editor.
3. Add the following NuGet reference:
```xml
<PackageReference Include="System.Memory" IncludeAssets="None">
<Version>4.5.4</Version>
</PackageReference>
```
<Note>
OR

It's important to add the `IncludeAssets` as `None`, or this fix will not work.
`Attempting to JIT compile method 'System.Text.Json.JsonElement Sentry.Internal.Json:Parse (byte[])' while running in aot-only mode.`

To help you debug the issue, add the following line to into your iOS project:

```csharp
_ = new byte[2].AsMemory();
```

You will notice a conflict of Assemblies in regard to AsMemory extension, the same is happening with the Sentry SDK but only reveals the issue in runtime.

![System.Memory conflict](system-memory-conflict.png)

To solve this, you will need to follow the steps below:

1. Edit your iOS 'csproj'
* `Visual Studio (Mac)`: Right-click on your iOS project and at the bottom, select the option `Edit Project File`.
* `Visual Studio (Windows)`: Right-click on your iOS project, select the option `Unload Project`. By doing that action, it'll open your raw project solution, otherwise, right-click your iOS project and select the option `Edit project file`.

<Note>
You can also use an external text editor or another IDE to edit your iOS project.
</Note>

4. Save and open your IDE
5. Wait for the IDE to restore the packages. Once finished, try to capture an exception or transaction
2. Locate the `ItemGroup` that contains `PackageReference`.

![ItemGroup with packagereference](finding-package-reference.png)

3. Add a new `packagereference` as shown on the snippet:

Another way to validate if the problem is happening on an iOS project is by adding the following code to your iOS project, to check if there's a conflict:
```csharp
_ = new byte[2].AsMemory();
<PackageReference Include="System.Memory" Version="4.5.4" IncludeAssets="None" />
```

<Note>
It's important to add the `IncludeAssets` as `None`, or this fix will not work.
</Note>

<Note>
Using Reference will not work, it must be PackageReference.
</Note>

4. Save the edited `csproj` file and reload your project if it was unloaded:
* `Visual Studio (Windows)`: Right-click on your iOS project, select the option `Reload Project`.
5. If the extension `AsMemory` keeps showing the conflict you will need to restart your IDE to make sure the changes are applied.
6. Wait for the IDE to restore the packages. Once finished, try to capture an exception or transaction.
7. If the extension `AsMemory` is still showing as conflicted, double-check if you executed step 3 exactly as shown.
8. With the problem solved, you will no longer require the test code into your solution.

More information about this problem can be found here: https://github.com/mono/mono/issues/20805

## tvOS

You may encounter the following issue on a tvOS project:

### Build issues

`linker command failed with exit code 1 (use -v to see invocation)`
`MTOUCH : error MT5216: Native linking failed for '.../libSystem.Reflection.Metadata.dll.dylib'. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new`

If this message displays in your build window when building your tvOS solution, you will need an additional mtouch argument in the project's iOS Build options (for all device configurations)

1. Open your iOS project properties.
2. On `tvOS Build` locate the `Additional mtouch arguments` entry.
3. add the following line

`--dlsym:System.Reflection.Metadata.dll`

4. Make sure the `additional mtouch argument` is applied to all configurations and platforms.
![iOS project mtouch arguments](tvos-metadata.jpg)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 0b3e918

@vercel
Copy link

@vercel vercel bot commented on 0b3e918 Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.