问题
I am working with Xamarin Forms on a message sending application with SignalR, which I have tested countless times locally and on Android and it works fine without crashes, but when they do the tests to upload it to the microsoft store they report that my application crashes .
According to the App center, the application crashes when they trying to send a message through SignalR, this is the error:
< SendPrivateMessageAsync> d__46.MoveNext () + 0x14b System.Reflection.MissingMetadataException: This operation cannot be carried out because metadata for the following object was removed for performance reasons:\n\n EETypeRva:0x0035FCD8\n\nNo further information is available. Rebuild in debug mode for better information.\n\n
System.Reflection.Runtime.TypeInfos
RuntimeNoMetadataNamedTypeInfo.get_InternalFullNameOfAssembly () f:\dd\ndp\fxcore\CoreRT\src\System.Private.Reflection.Core\src\System\Reflection\Runtime\TypeInfos\RuntimeBlockedTypeInfo.cs at 240:17
System.Text.Json
JsonPropertyInfo.Initialize (Type, Type, Type, Type, PropertyInfo, Type, JsonConverter, JsonSerializerOptions) + 0x11f
System.Text.Json
JsonPropertyInfoCommon`4.Initialize (Type, Type, Type, Type, PropertyInfo, Type, JsonConverter, JsonSerializerOptions) + 0x:59
System.Text.Json
JsonClassInfo.CreateProperty (Type, Type, Type, PropertyInfo, Type, JsonConverter, JsonSerializerOptions) + 0x2f:2
System.Text.Json
JsonClassInfo.AddProperty (Type, PropertyInfo, Type, JsonSerializerOptions) + 0x9e
System.Text.Json
JsonClassInfo.AddPolicyProperty (Type, JsonSerializerOptions) + 0x2f
System.Text.Json.JsonClassInfo
+ 0xdd:1
System.Text.Json
JsonSerializerOptions.GetOrAddClass (Type) + 0x:71
System.Text.Json
WriteStackFrame.Initialize (Type, JsonSerializerOptions) + 0x:13
System.Text.Json
JsonSerializer.WriteCore (Utf8JsonWriter, Object, Type, JsonSerializerOptions) + 0x8d
System.Text.Json
JsonSerializer.WriteValueCore (Utf8JsonWriter, Object, Type, JsonSerializerOptions) + 0x3e
Microsoft.AspNetCore.SignalR.Protocol
JsonHubProtocol.WriteArguments (Object[], Utf8JsonWriter) + 0x1ef
Microsoft.AspNetCore.SignalR.Protocol
JsonHubProtocol.WriteStreamInvocationMessage (StreamInvocationMessage, Utf8JsonWriter) + 0x:65
Microsoft.AspNetCore.SignalR.Protocol
JsonHubProtocol.WriteMessageCore (HubMessage, IBufferWriter`1) + 0x55d
Microsoft.AspNetCore.SignalR.Protocol
JsonHubProtocol.WriteMessage (HubMessage, IBufferWriter`1) + 0xc
Microsoft.AspNetCore.SignalR.Client.HubConnection
<SendHubMessage>d__72.MoveNext () + 0x7f
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices
TaskAwaiter.ThrowForNonSuccess (Task) + 0x:70
System.Runtime.CompilerServices
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task) + 0x:38
System.Runtime.CompilerServices
TaskAwaiter.ValidateEnd (Task) + 0x:17
System.Runtime.CompilerServices
TaskAwaiter.GetResult () + 0xb
Microsoft.AspNetCore.SignalR.Client.HubConnection
<InvokeCore>d__70.MoveNext () + 0x:194
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices
TaskAwaiter.ThrowForNonSuccess (Task) + 0x:70
System.Runtime.CompilerServices
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task) + 0x:38
System.Runtime.CompilerServices
TaskAwaiter.ValidateEnd (Task) + 0x:17
Microsoft.AspNetCore.SignalR.Client.HubConnection
<InvokeCoreAsyncCore>d__69.MoveNext () + 0x:335
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices
TaskAwaiter.ThrowForNonSuccess (Task) + 0x:70
System.Runtime.CompilerServices
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task) + 0x:38
System.Runtime.CompilerServices
TaskAwaiter.ValidateEnd (Task) + 0x:17
System.Threading.Tasks
ForceAsyncAwaiter`1.GetResult () + 0x:18
Microsoft.AspNetCore.SignalR.Client.HubConnection
<InvokeCoreAsync>d__56.MoveNext () + 0x:105
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices
TaskAwaiter.ThrowForNonSuccess (Task) + 0x:70
System.Runtime.CompilerServices
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task) + 0x:38
System.Runtime.CompilerServices
TaskAwaiter.ValidateEnd (Task) + 0x:17
System.Runtime.CompilerServices
TaskAwaiter.GetResult () + 0xb
Chat.Shared.Core.ChatService
<SendPrivateMessageAsync>d__46.MoveNext () + 0x14b
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices
TaskAwaiter.ThrowForNonSuccess (Task) + 0x:70
System.Runtime.CompilerServices
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task) + 0x:38
System.Runtime.CompilerServices
TaskAwaiter.ValidateEnd (Task) + 0x:17
System.Runtime.CompilerServices
TaskAwaiter.GetResult () + 0xb
MyClinicalApp.ViewModels.ChatViewModel.<>c__DisplayClass39_1
<<SendMessage>b__1>d.MoveNext () + 0x:137
System.Runtime.ExceptionServices
ExceptionDispatchInfo.Throw () + 0x:21
System.Runtime.CompilerServices.AsyncMethodBuilderCore
<>c.<ThrowAsync>b__7_0 (Object) + 0x1e
System
Action`1.Invoke (T) + 0x:28
System.Threading.WinRTSynchronizationContext
Invoker.InvokeCore () + 0x:33
System.Runtime.InteropServices
McgMarshal.ThrowOnExternalCallFailed (Int32, RuntimeTypeHandle) + 0x:21
__Interop
ComCallHelpers.Call (__ComObject, RuntimeTypeHandle, Int32) + 0xb:8
__Interop
ForwardComStubs.Stub_15[TThis] (__ComObject, Int32) + 0x:24
Microsoft.AppCenter.Utils
ApplicationLifecycleHelper.<ctor>b__17_1 (Object, UnhandledErrorDetectedEventArgs) + 0x3d
If someone can give me any tips or advice on how to determine the error. thank you.
P.S. I have also tried Upload debug symbols but I think there is an error in the app center page or I'm probably doing something wrong, the problem is that after about 20min trying to upload the page is cleaned and nothing was ever uploaded, this process will I have tried 7 times and I never manage to upload the .appxsym
回答1:
The problem you are seeing is caused by the .NET Native toolchain stripping away code to make the assembly smaller and faster. Unfortunately, .NET Native is not smart enough to understand when a type needs to be reflected upon and may sometimes remove metadata which you in fact require.
Debugging this is a bit complicated, as you need to try out for which type exactly the metadata are required and missing and mark this type as required in the Default.rd.xml
file, which you can find in the Properties
folder in your UWP project. There is a very useful on-line .NET Native MissingMetadataException troubleshooter. Which is designed to auto-generate the proper rd.xml syntax for you. Only thing you need to do is fill out the type/namespace names and specify how the types are reflected.
To get to the exact root of the problem, switch the build configuration to Release
in Visual Studio and then run the application and observe at which point it crashes. It sometimes also helps to comment and uncomment code to figure out the exact place when it happens. In your case I suspect that it is due to JSON serialization and deserialization, which can often happens, as the types are used only for this sole purpose and the properties "appear" as if not referenced anywhere.
回答2:
Thanks to Martin Zikmund for helping me understand the problem.
In order to discover the root of the error it was necessary to compile in DEBUG configuration with .NET Native enabled (Project Properties> Build> Enable ".NET Native tool Chain" checkbox). In this way, I was able to determine which MissingMetadataException was, and thus be able to form the rd.xml file correctly.
In my case, it was corrected in this way:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.JsonConverterString" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.JsonConverterBoolean" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.JsonConverterObject" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.JsonConverterByteArray" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.JsonConverterDateTime" Dynamic="Required All" />
</Application>
</Directives>
Thanks also to Jarvan y Matthew Whilden to for their time and help me solve it.
来源:https://stackoverflow.com/questions/59650405/uwp-xamarin-crash-in-submission-tests-when-i-try-to-upload-a-microsoft-store