xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.48k stars 514 forks source link

Failure to initialize an NSObject when using 3rd party framework #10733

Closed shaytate closed 1 month ago

shaytate commented 3 years ago

Steps to Reproduce

  1. Install the Opentok binding for ios nuget Xamarin.OpenTok.iOS -Version 2.18.1
  2. Create a new Session object with: Session = new OTSession(ApiKey, SessionId, null)
  3. Initialize the session : Session.Init()

Also want to mention my environment:

Expected Behavior

Init is called without error

Actual Behavior

I get the following exception:

{System.Exception: you have not allocated the native object at Foundation.NSObject.Init () [0x00012] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject.iOS.cs:33 at MyProject.iOS.DependencyClasses.SIP.ConnectToSession () [0x001fe] in C:\Workspace\TEKWave\MyProject\MyProject.iOS\DependencyClasses\SIP.cs:50 }

Also want to mention that the class handle and handle within the session object once it's created shows the following:

Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue'.

And the superhandle shows the following:

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'OTSession'.

Environment

Microsoft Visual Studio Professional 2019
Version 16.8.6
VisualStudio.16.Release/16.8.6+31019.35
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2019   00435-60000-00000-AA747
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.8.560.26713
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.560.26713
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.8.560.26713
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.8.560.26713
Azure Functions and Web Jobs Tools

C# Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.8.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62102.01130
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.21016.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.262 (d16-8@4d60f9c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.26 (d16-8/a36ce73)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

Xamarin.iOS and Xamarin.Mac SDK   14.10.0.4 (5a05865f6)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Rebuild started... NU1603: Xamarin.Firebase.Messaging 121.0.1 depends on Xamarin.Google.Android.DataTransport.TransportRuntime (>= 2.2.4) but Xamarin.Google.Android.DataTransport.TransportRuntime 2.2.4 was not found. An approximate best match of Xamarin.Google.Android.DataTransport.TransportRuntime 2.2.5 was resolved. NU1603: Xamarin.Firebase.Messaging 121.0.1 depends on Xamarin.Google.Android.DataTransport.TransportRuntime (>= 2.2.4) but Xamarin.Google.Android.DataTransport.TransportRuntime 2.2.4 was not found. An approximate best match of Xamarin.Google.Android.DataTransport.TransportRuntime 2.2.5 was resolved. 1>------ Rebuild All started: Project: MyProjectResidential.Standard, Configuration: Debug Any CPU ------ 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Converters\InvertBoolConverter.cs(26,30,26,31): warning CS0168: The variable 'e' is declared but never used 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\AppShellViewModel.cs(140,13,140,32): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\VisitorTempListPageViewModel.cs(108,28,108,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\VisitorPermListPageViewModel.cs(108,28,108,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\VisitorPageViewModel.cs(438,21,438,32): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\XmlSerializerHelper.cs(35,30,35,31): warning CS0168: The variable 'e' is declared but never used 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\XmlSerializerHelper.cs(52,30,52,33): warning CS0168: The variable 'exp' is declared but never used 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\Util.cs(102,17,102,41): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\Util.cs(100,54,100,56): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\PartyListPageViewModel.cs(45,28,45,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Components\CustomBindablePicker.cs(361,62,361,104): warning CS0618: 'SelectedItemChangedEventArgs.SelectedItemChangedEventArgs(object)' is obsolete: 'This constructor is obsolete as of version 3.5. Please use SelectedItemChangedEventArgs(object selectedItem, int selectedItemIndex) instead.' 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\ProfilePages\ProfilePetListViewModel.cs(45,28,45,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\ProfilePages\ProfileVacationListViewModel.cs(45,28,45,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\ProfilePages\ProfileVehicleListViewModel.cs(47,28,47,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\Util.cs(174,21,174,35): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\ViewModels\ProfilePages\ProfileHouseholdListViewModel.cs(45,28,45,51): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\Sync.cs(998,46,998,48): warning CS0168: The variable 'ex' is declared but never used 1>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\Helpers\Sync.cs(1088,46,1088,48): warning CS0168: The variable 'ex' is declared but never used 1>MyProjectResidential.Standard -> C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.Standard\bin\Debug\netstandard2.0\MyProjectResidential.Standard.dll 1>Done building project "MyProjectResidential.Standard.csproj". Apple Support - iTunes installed: 'True', Installation type: 'Store' 2>------ Rebuild All started: Project: MyProjectResidential.iOS, Configuration: Debug iPhone ------ 2> Detected signing identity: 2> Code Signing Key: "Apple Development: My Name (identifier)" (C:\Users\Name\AppData\Local\Xamarin\iOS\Provisioning\Certificates\p12id.p12) 2> Provisioning Profile: "App Development" (C:\Users\Name\AppData\Local\Xamarin\iOS\Provisioning\Profiles\profileid.mobileprovision) 2> Consider app.config remapping of assembly "System.Runtime.CompilerServices.Unsafe, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.4.1" [] to Version "4.0.6.0" [C:\Users\Name.nuget\packages\system.runtime.compilerservices.unsafe\4.7.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll] to solve conflict and get rid of warning. 2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. 2>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.iOS\DependencyClasses\SIP.cs(56,30,56,32): warning CS0168: The variable 'ex' is declared but never used 2>C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.iOS\DependencyClasses\SIP.cs(199,30,199,32): warning CS0168: The variable 'ex' is declared but never used 2> MyProjectResidential.iOS -> C:\Workspace\MyProject\MyProjectResidential\MyProjectResidential.iOS\bin\iPhone\Debug\MyProjectResidential.iOS.exe ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

Example Project (If Possible)

None

VS bug #1286663

rolfbjarne commented 3 years ago

This code works for me:

var session = new OTSession ("ApiKey", "SessionId", null);
session.Init ();

Please attach a complete sample project we can use to reproduce this.

shaytate commented 3 years ago

See attached sample Sample.zip

rolfbjarne commented 3 years ago

Your sample still works for me.

Do you see this error on both the simulator and on device?

Could you please attach a full build log as well? Please remember to clean your project first (otherwise nothing will actually be built).

To get full build logs, set the log verbosity to diagnostic at the following locations:

Then save the output to a file and attach it here.

shaytate commented 3 years ago

I am using an iphone 7 device. I found that while it fails on the device, it does not fail on the iphone 7 simulator. Attached is the build log. build_log.txt

rolfbjarne commented 3 years ago

It seems you have hot restart enabled, can you try disabling that and see if that works:

IsHotRestartBuild = True

shaytate commented 3 years ago

Visual Studio won't allow me to select my iphone when I have hot restart disabled. It doesn't show as an option.

rolfbjarne commented 3 years ago

Are you connected to a Mac?

shaytate commented 3 years ago

I'm using VS on a Windows 10 PC and connected to remote Mac

rolfbjarne commented 3 years ago

The problem is that Xamarin.OpenTok.iOS is not compatible with Hot Restart because it contains a binding to a native library, and for some reason you can't disable Hot Restart because then you can't debug on your phone.

This seems to be an issue specific to Visual Studio for Windows, so I'm assigning it to the corresponding team.

shaytate commented 3 years ago

Thank you

burrowj commented 3 years ago

I can't turn off Hot Restart either since i upgraded to Visual Studio 16.9.2 I've submitted an issue as well

rolfbjarne commented 1 month ago

The VS issue has been closed.