Device build failed with MT0000 Object reference not set to an instance of an object error
kimhongka opened this issue · 16 comments
Steps to Reproduce
- I've got Xamarin iOS binding library project
- I can build and deploy the sample app on Simulator
- Failed on Device build (Debug|Iphone or Release|Iphone)
Expected Behavior
Build without the null exception error
Actual Behavior
Failed to build and got the above error
Environment
Xcode Version 11.5 (11E608c)
Visual Studio Community 2019 for Mac
Version 8.6.4 (build 14)
Installation UUID: c50b325e-2351-4fd2-81ae-720a93b99250
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c736)
Package version: 610000104
Mono Framework MDK
Runtime:
Mono 6.10.0.104 (2019-12/5d03a6fe116) (64-bit)
Package version: 610000104
Roslyn (Language Service)
3.6.0-3.20210.9+4eafdcb1bcbd8d3573f2ba6065e56d9b9ce4f8a3
NuGet
Version: 5.6.0.6591
.NET Core SDK
SDK: /usr/local/share/dotnet/sdk/3.1.301/Sdks
SDK Versions:
3.1.301
3.1.300
3.1.200
3.1.102
3.1.101
3.1.100
3.1.100-preview2-014569
3.0.100
2.2.100
2.1.701
2.1.700
2.1.508
2.1.302
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.10.0/lib/mono/msbuild/Current/bin/Sdks
.NET Core Runtime
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.5
3.1.4
3.1.2
3.1.1
3.1.0
3.1.0-preview2.19525.6
3.0.0
2.2.0
2.1.19
2.1.18
2.1.16
2.1.15
2.1.14
2.1.13
Xamarin.Profiler
Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Apple Developer Tools
Xcode 11.5 (16139)
Build 11E608c
Xamarin.Mac
Version: 6.18.2.1 (Visual Studio Community)
Hash: 29c4ea7
Branch: d16-6
Build date: 2020-05-26 17:03:04-0400
Xamarin.iOS
Version: 13.18.2.1 (Visual Studio Community)
Hash: 29c4ea7
Branch: d16-6
Build date: 2020-05-26 17:03:05-0400
Xamarin Designer
Version: 16.6.0.329
Hash: d4f8bcd13
Branch: remotes/origin/d16-6
Build date: 2020-04-24 02:16:02 UTC
Xamarin.Android
Version: 10.3.1.4 (Visual Studio Community)
Commit: xamarin-android/d16-6/3a10de9
Android SDK: /Users/thonggyu/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.6
SDK Build Tools Version: 29.0.2
Build Information:
Mono: 165f4b0
Java.Interop: xamarin/java.interop@2cab35c
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@49232bc
Xamarin.Android Tools: xamarin/xamarin-android-tools@bfb66f3
Microsoft OpenJDK for Mobile
Java SDK: /Users/thonggyu/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Android SDK Manager
Version: 16.6.0.50
Hash: 5901879
Branch: remotes/origin/d16-6
Build date: 2020-05-15 00:43:06 UTC
Android Device Manager
Version: 16.6.0.95
Hash: 45d17b5
Branch: remotes/origin/d16-6
Build date: 2020-05-15 00:43:26 UTC
Build Information
Release ID: 806040014
Git revision: b22fa17f4309e67d2f254d93f02d17613cf6ef6c
Build date: 2020-06-15 10:43:44-04
Build branch: release-8.6
Xamarin extensions: b22fa17f4309e67d2f254d93f02d17613cf6ef6c
Operating System
Mac OS X 10.15.5
Darwin 19.5.0 Darwin Kernel Version 19.5.0
Tue May 26 20:41:44 PDT 2020
root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
Enabled user installed extensions
NuGet Package Management Extensions 0.20
Build Logs
1>/Users/thonggyu/Desktop/DotDigital22062020/12062020WorkingCMPComapiFoundation-binding 2/TestPushNotification/MTOUCH(0,0): Error MT0000 : Unexpected error - Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new
1>System.NullReferenceException: Object reference not set to an instance of an object
1> at Registrar.StaticRegistrar.Specialize (Registrar.AutoIndentStringBuilder sb) [0x00dcf] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/StaticRegistrar.cs:2971
1> at Registrar.StaticRegistrar.Generate (System.String header_path, System.String source_path) [0x00177] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/StaticRegistrar.cs:4859
1> at Registrar.StaticRegistrar.Generate (System.Collections.Generic.IEnumerable`1[T] assemblies, System.String header_path, System.String source_path) [0x0007b] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/StaticRegistrar.cs:4822
1> at Xamarin.Bundler.RunRegistrarTask.Execute () [0x00001] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/mtouch/BuildTasks.mtouch.cs:166
1> at Xamarin.Bundler.BuildTask.b__23_0 () [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:285
1> at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-12/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2476
1> at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-12/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
1>--- End of stack trace from previous location where exception was thrown ---
1>
1> at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:270
1> at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:270
1> at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x000f1] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:241
1> at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x0038c] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:274
1> at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:270
1> at Xamarin.Bundler.BuildTasks+<>c__DisplayClass4_0.b__0 () [0x0002e] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/BuildTasks.cs:50 .
Example Project (If Possible)
Thank you for your feedback!
For us to investigate this further, could you please provide your full build logs, crash reports (if any), test case (to reproduce) and all your version information.
To get full build logs just set the log verbosity to diagnostic at the following locations:
- On Visual Studio for Mac: Preferences > Projects > Build
- On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run
On Visual Studio for Windows you also want to add -v -v -v -v
to the mtouch additional arguments by right-clicking the project in the solution explorer and selecting Properties
.
Note: this is done automatically on Visual Studio for Mac when the log verbosity is set to diagnostic.
The easiest way to get exact version information:
- On Visual Studio for Mac: "Visual Studio" menu, "About Visual Studio" item, "Show Details" button.
- On Visual Studio for Windows: "Help menu", "About Microsoft Visual Studio" item.
Then copy/paste the version information (you can use the "Copy Information" button).
We look forward to hearing from you!
@chamons Thank you for the response, I've added the detail before, but it has been commented and it is now visible. I have a sample project with me but it is about 250 MB. Is there any way that I can upload the zip file?
This is the part that we need to address..
1>System.NullReferenceException: Object reference not set to an instance of an object
1> at Registrar.StaticRegistrar.Specialize (Registrar.AutoIndentStringBuilder sb) [0x00dcf] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tools/common/StaticRegistrar.cs:2971
@kimhongka - Try removing the obj and bin directories and check your size again, often people forget to remove them and it can increase the size of samples by tenfold or more.
The sample project can be built on Debug|iPhoneSimulator but not on Debug|iPhone
The below line brings the build issue.
CMPAuthenticationChallenge d = null; in ViewController in TestPushNoticiation
There are two Xamarin.iOS binding library projects and CMPComapiFoundation one is not available to be called on Device build.
I can confirm the tooling crash with the sample provided.
Cool, thank you for the confirmation. Please let me know if there is any option to address this issue like using Pre-release version of Xamarin.ios or downgrade the version. Thank you again with this quick response~
There is a bug in our generator, but I have a work around you can apply.
- Remove the generic on CMPResult and all locations which use it as generic
- In general C# generics in bindings is documented as discouraged as it requires run-time lookup of types, so this shouldn't be too terrible of a workaround.
Hey @rolfbjarne - This test case hits this warning
// I believe the generic constraints we have should make this error impossible to hit, but better safe than sorry.
AddException (ref exceptions, CreateException (4167, inMethod.Resolve () as MethodDefinition, "Cannot register the method '{0}' because the signature contains a generic type ({1}) with a generic argument type that doesn't implement INativeObject ({2}).", descriptiveMethodName, GetTypeFullName (type), GetTypeFullName (argumentType)));
https://github.com/xamarin/xamarin-macios/blob/main/tools/common/StaticRegistrar.cs#L2371
I am looking into why we are NRE instead of reporting the real exception however.
Ah:
inMethod.Resolve () as MethodDefinition
inMethod is null here
We get that passed in as method.Method, which is null
@chamons Thank you for the workaround solution. I found the exact place that it is cause of this issue.
if you commented out
//[Abstract]
//[Export("resultFromData:urlResponse:netError:")]
//CMPResult ResultFromData(NSData data, NSUrlResponse response, [NullAllowed] NSError netError);
in CMPComapiFoundation in ApiDefinition.cs
It enable app to be build on Device.
It must be related to CMPResult Generic interface part, I have removed all the generic part before, I could build the app, but the actual functionality of the methods that is using the CMPResult were not working properly.
Since I don't need to use the ResultFromData method so far, I will just comment it out for now.
However, I still believe the null reference exception should be fixed.
I will keep tracking this issue ticket. Please let me know if there are anything that I can help you out to address the actual issue.
Thank you again :)
Yep, the binding tooling should never crash, even with questionable input, so keeping it open is the right call.
Given Xcode 12, it may be awhile until this get nailed down - I'm glad you are unblocked.
Hi there,
I faced the similar issue :( when running my sample app targeting real device.
Can anyone help check?
Regards.
MTOUCH : error MT0000: Unexpected error - Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new
System.NullReferenceException: Object reference not set to an instance of an object
at Registrar.StaticRegistrar.Specialize (Registrar.AutoIndentStringBuilder sb, System.String& initialization_method) [0x00e28] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/StaticRegistrar.cs:3107
at Registrar.StaticRegistrar.Generate (System.String header_path, System.String source_path, System.String& initialization_method) [0x0018c] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/StaticRegistrar.cs:5201
at Registrar.StaticRegistrar.Generate (MonoTouch.Tuner.MonoTouchResolver resolver, System.Collections.Generic.IEnumerable`1[T] assemblies, System.String header_path, System.String source_path, System.String& initialization_method) [0x0008b] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/StaticRegistrar.cs:5163
at Registrar.StaticRegistrar.Generate (System.Collections.Generic.IEnumerable`1[T] assemblies, System.String header_path, System.String source_path, System.String& initialization_method) [0x00001] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/StaticRegistrar.cs:5146
at Xamarin.Bundler.RunRegistrarTask.Execute () [0x00001] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/mtouch/BuildTasks.mtouch.cs:123
at Xamarin.Bundler.BuildTask.<ExecuteAsync>b__23_0 () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:280
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2476
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x002a9] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:254
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x0038c] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:269
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:265
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:265
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:265
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x000f1] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:236
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x0038c] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:269
at Xamarin.Bundler.BuildTask.Execute (Xamarin.Bundler.BuildTasks build_tasks) [0x00368] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:265
at Xamarin.Bundler.BuildTasks+<>c__DisplayClass4_0.<ExecuteBuildTasks>b__0 () [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/tools/common/BuildTasks.cs:47
@tuyen-vuduc can you get a binlog (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs) for a failing build?
Hi @rolfbjarne ,
I sent it the other day on Discord.
I attached it again here.
I also tried to build this repo, but failed with the log here.
MapboxMauiQs_Debug_Build_2023-07-25T15_54_50.9096730Z.binlog.zip