I recently tried to recompile a project that had been working in a newer version of Xamarin. The project compiles, but crashes on the device with an invalid cast exception.
System.InvalidCastException: Cannot cast from source type to destination type.
The crash occurs in designer generated code:
[MonoTouch.Foundation.Connect("turnOnAnimation")]
private MonoTouch.UIKit.UIImageView turnOnAnimation {
get {
object test = this.GetNativeField ("turnOnAnimation");
**this.__mt_turnOnAnimation = ((MonoTouch.UIKit.UIImageView)(this.GetNativeField("turnOnAnimation")));**
return this.__mt_turnOnAnimation;
}
set {
this.__mt_turnOnAnimation = value;
this.SetNativeField("turnOnAnimation", value);
}
}
Studying the return from GetNativeField, I seem to be getting a UIView instead of a UIImageView back:
But the outlet in the XIB is connected to a UIImageView.
To my knowledge this code was working fine with earlier versions. Has something changed in recent versions or should I be doing something differently?
Additional testing showed:
1) This problem occurred on an iPod touch running iOS version 7.1.1
2) The problem did not occur in the simulator running iOS 8.1 (any iOS platform)
3) The problem did not occur on an iPhone running 8.1.2
4) Upgrading the iPod touch to iOS 8.1.3 resolved the issue.
I conclude this was either an iOS bug or an incompatibility between current Xamarin tooling and the older version of iOS.
Related
I recently tried to implement Microsoft.AppCenter.Crashes to help track down crashes in my team's Xamarin.Forms app. However, when a crash happens on our iOS project, AppCenter never detects it. I've created the following function for setup and checking, which gets called near the start of our central project's App.xaml.cs App constructor:
private async Task CheckForPreviousCrash()
{
//Setup AppCenter
await Xamarin.Forms.Device.InvokeOnMainThreadAsync(() =>
{
//Keys changed in StackOverflow post for security reasons.
AppCenter.Start("ios=########-####-####-####-############;android=########-####-####-####-############;uwp=########-####-####-####-############", typeof(Crashes));
AppCenter.IsNetworkRequestsAllowed = false; //Prevents sending user data to Microsoft. Required by company
});
//Make sure AppCenter is working
bool isEnabled = await Crashes.IsEnabledAsync();
if (!isEnabled)
{
_logger.LogError("AppCenter could not be started");
}
else
{
//Check for memory leak warnings
bool memoryIssue = await Crashes.HasReceivedMemoryWarningInLastSessionAsync();
if (memoryIssue)
{
_logger.LogError("AppCenter detected a memory warning in the last session");
}
//Check for crash info
bool crashed = await Crashes.HasCrashedInLastSessionAsync();
if (crashed)
{
var report = await Crashes.GetLastSessionCrashReportAsync();
_logger.LogCrashReport(report);
}
//If AppCenter detected no issues in the last session, log an "all clear" message
if (!memoryIssue && !crashed)
{
_logger.LogInformation("AppCenter did not detect a crash in the last session");
}
}
}
I've tested this code using the Crashes.GenerateTestCrash() function, one of the crashes my team is trying to resolve, and a simple recursive function that calls itself forever. When run on iOS, our logs will always show the "AppCenter did not detect a crash in the last session" message, regardless of if a crash occurred. Any help determining what could be causing this would be appreciated.
Notes:
The iOS project is always run without a debugger attached. I'm aware of the rule that crash reports will not be generated if iOS has a debugger attached
This has been seen when built using both Debug and Release mode
This code works as expected on our Android and UWP projects
The iOS project always passes the isEnabled check
This is running AppCenter and AppCenter.Crashes version 4.5.0
This is running on a 7th gen iPad on iOS 15.2.1
EDIT: Extra notes in response to a suggested answer:
The Mac used to build the iOS project is running macOS 11.6.2
Project is built using XCode 13.2.1
The Xamarin Forms project is built in Visual Studio 2019 16.11.7, and sent to the connected mac via Visual Studio's "Pair to Mac" feature
There are no other libraries used for crash reporting (the closest used is Serilog, which should only be handling logging)
We do not use CocoaPods to integrate AppCenter
You can check if you meet the requirements as following shows:
-Your iOS project is set up in Xcode 11 or later on macOS version 10.14.4 or later.
-You're targeting devices running on iOS 9.0 or later.
-You're not using any other library that provides Crash Reporting functionality (only for App Center Crashes).
-If you are using CocoaPods to integrate App Center, you need CocoaPods version 1.10 or later.
App Center SDK Analytics and Crashes are compatible with Mac Catalyst via XCFramework or SwiftPM.
Here are more detail about appcenter crashed on ios https://learn.microsoft.com/en-us/appcenter/sdk/getting-started/ios
I've been a developer Unity iOS developer for a while now and I recently tried to test out my app on my phone. After building the project and uploading it to xCode so I can upload the app on my phone, the app was developed but crashes once I opened it. There are some warning logs but not sure which one is causing the crashing.
https://i.stack.imgur.com/FKY8e.jpg
https://i.stack.imgur.com/D4ryX.png
I also might think this is because I am not paying for the Apple developer program, yet before I was able to test it without paying for it.
Logs:
2020-03-28 14:11:21.207192-0700 TheSuccFinal[2733:973093] Error loading /var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework, 265): no suitable image found. Did find:
/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: code signature invalid for '/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework'
/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: stat() failed with errno=3
/private/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: code signature invalid for '/private/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework'
2020-03-28 14:11:21.247919-0700 TheSuccFinal[2733:973093] Error loading /var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework, 265): no suitable image found. Did find:
/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: code signature invalid for '/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework'
/private/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework.framework/UnityFramework: code signature invalid for '/private/var/containers/Bundle/Application/A8DD7379-FF01-4A00-AF26-77A546A87C8E/TheSuccFinal.app/Frameworks/UnityFramework
It is related to iOS 13.3.1 since recent releases from Apple iOS builder, personal (non-developer) Apple accounts cannot sign frameworks correctly, since Unity is a framework itself it is not signed when built.
You can check this unity forum discussion and this discussion in the flutter framework about the bug.
Apparently it is fixed in iOS 13.4, so check your XCode version, iOS target version and you should be good to go.
I am trying run a Xamarin iOS app on a device with Visual Studio. However I get the following error:
Error MT4116: Could not register the assembly 'Xamarin.Auth.iOS':
error MT4118: Cannot register two managed types
('Xamarin.Controls.ProgressLabel, Xamarin.Auth.iOS' and
'Xamarin.Controls.ProgressLabel, Xamarin.Auth') with the same native
name ('Xamarin_Controls_ProgressLabel'). (MT4116)
The ProgressLabel class seems to be defined in Xamarin.Auth.iOS and Xamarin.Auth twice.
Does anyone have an idea how to solve this?
I have an UWP app written in C# which builds (VS 14.0.25425.01 Update 3 on Windows 10.0.14393, target version of the project is build 14393) and runs in Debug mode, but fails to build in Release mode with the following error:
Microsoft.NetNative.targets(640,5): error : MCG0004:InternalAssert Assert Failed: field not found during [UNKNOWN]
There are no further details, except for two warnings before, which I am not sure whether they are related to the problem:
Resources.System.Linq.Expressions.rd.xml(35): warning : ILTransform : warning ILT0027: Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found.
Resources.System.Linq.Expressions.rd.xml(91): warning : ILTransform : warning ILT0027: Method 'ParameterIsAssignable' within 'System.Linq.Expressions.Expression' could not be found.
Any suggestions what the issue could be related to?
This error will occur if you're using the Beta package for .NET UWP tools with VS 2015. The Beta package is only supported on 2017 as there are changes to how deployment/debugging work that we rely on. You should be able to avoid the issue by downgrading from "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.0-beta2" to "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
edit: 5.3.0 has been published and works with VS2017 RC3+. More information here: https://blogs.msdn.microsoft.com/dotnet/2017/01/30/announcing-net-core-net-native-and-nuget-updates-in-vs-2017-rc/
Disclaimer: I work on the .NET Native compiler+runtime team.
I am using Windows Update API (WUApiLib) in a C# .NET 2.0 project.
I get the following error on Windows XP (in Windows 7 it works alright):
"System.MissingMethodException: Method not found: 'WUApiLib.UpdateSearcher WUApiLib.UpdateSessionClass.CreateUpdateSearcher()'."
This is my code:
WUApiLib.UpdateSessionClass session = new WUApiLib.UpdateSessionClass();
WUApiLib.IUpdateSearcher searcher = session.CreateUpdateSearcher();
WUApiLib.ISearchResult result = searcher.Search("Type='Software'");
if (result.Updates.Count > 0)
{
//do stuff
}
The error occurs at runtime, the compiler shows no errors...
Does anybody know why I get this error?
You are no doubt battling a version problem, the Win7 version is WUA version 2, XP is probably still stuck at 1. If you want to support XP then make sure to use an interop library that you generated with Tlbimp.exe on a XP machine. Keeps you out of trouble, you can't accidentally use an interface or method that isn't supported on XP.
I don't see much in the way of documentation for what's available in which version and to what degree version 2 is backwards compatible with version 1. Only this MSDN Library page seems relevant.