Troubleshooting: InvalidCastException
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- android, csharp
- Domain
- documentation, mobile-dev
Research direction
Start with the two linked Discord write-ups and the InvalidCastException example in this issue. Turn the Release-build type-linking explanation and the JavaCast() workaround into documentation, and consider the work done when a reader can diagnose this failure and apply the documented fix.
Written by the indexing model from the issue text.
Description
I wrote this up on Discord, and it should be massaged into documentation:
- https://discord.com/channels/732297728826277939/732297837953679412/1164976813513130014
- https://discord.com/channels/732297728826277939/732297837953679412/1165090944505368606
Context:
App has:
partial class DragListAdapter {
public DragListAdapter(AWidget.ListView listView, LinTest.Files.DragListView element)
{
try
{
WrappedAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
In Debug config build, it runs fine. In Release config, it throws:
V mono-stdout: # jonp: ERROR: System.InvalidCastException: Specified cast is not valid.
V mono-stdout: at DragListView.Android.Renderers.DragListAdapter..ctor (Android.Widget.ListView listView, LinTest.Files.DragListView element) [0x00070] in <15a302750fe049359ec667fe1a08adbe>:0
TL;DR: it fails in Release because a type is linked away. The fix/workaround is to use .JavaCast<T>():
WrappedAdapter = _listView.Adapter.JavaCast<AWidget.IWrapperListAdapter>().WrappedAdapter;
- Dominant language
- No language data
- Stars
- 4
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/docs-mobile
-
Difficulty 3/5 3-5 days Newbie friendliness 45/100
dotnet/docs-mobile#85 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
dotnet/docs-mobile#18 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
dotnet/docs-mobile#8 · 2 comments ·
All issues in dotnet/docs-mobile
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·