UWP - Object reference not set to an instance of an object - xamarin
After upgrading Microsoft.NETCore.UniversalWindowsPlatform I cannot compile my Xamarin app-project in Release anymore, as I get an Internal compiler error: Object reference not set to an instance of an object.
I am using these NuGet packages
Acr.UserDialogs 5.2.2
ExifLib.PCL 1.0.1 (in portable project)
Microsoft.NETCore.UniversalWindowsPlatform 5.2.0
MR.Gestures 1.3.4
Newtonsoft.Json 7.0.1 (in portable project)
Splat 1.6.2 (in portable project)
SQLite.Net.Core-PCL 3.1.1
SQLite.Net-PCL 3.1.1
Win2D.uwp 1.18.0 (in portable project)
Xam.Plugins.Settings 2.1.0
Xamarin.Forms 2.3.0.107
Xamarin.Insights 1.12.3
XLabs.Core 2.2.0-pre02
XLabs.Forms 2.2.0-pre02
XLabs.IoC 2.2.0-pre02
XLabs.Platform 2.2.0-pre02
XLabs.Serialization 2.2.0-pre02
A log can be found here.
I hope anybody in here can help me.
All platforms are set to Compile with .NET Native tool chain.
UPDATE
If I build XLabs myself and set Compile with .NET Native tool chain to unchecked. These errors occurs.
App manifest
Error Found: The app manifest test detected the following errors:
<project> takes a dependency on Microsoft .Net Native Runtime Package 1.x framework but is missing the framework dependency declaration in the manifest.
Binary analyzer
Error Found: The binary analyzer test detected the following errors:
File C:\Program Files\WindowsApps\<project>_1.8.0.0_x64__r1myykanma94r\clrjit.dll has failed the AppContainerCheck check.
Supported APIs
Error Found: The supported APIs test detected the following errors:
API SystemFunction036 in advapi32.dll is not supported for this application type. clrjit.dll calls this API.
API DebugBreak in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API HeapValidate in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API LoadLibraryExW in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API RtlCaptureContext in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API RtlVirtualUnwind in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API TlsAlloc in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API TlsFree in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API TlsGetValue in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API TlsSetValue in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API UnhandledExceptionFilter in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API VirtualAlloc in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API VirtualProtect in kernel32.dll is not supported for this application type. clrjit.dll calls this API.
API ExecuteAssembly in uwphost.dll is not supported for this application type. <project>.exe calls this API.
API DllGetActivationFactory in uwphost.dll is not supported for this application type. <project>.UWP.exe has an export that forwards to this API.
UPDATE 2
I could easily rewrite the code, so I did not use Win2D.uwp anymore. Somehow I have installed Microsoft.NETCore.UniversalWindowsPlatform v 5.2.0 last friday, but the latest in NuGet is now v 5.1.0.
So now I am down to these NuGet packages
Acr.UserDialogs 5.3.0
ExifLib.PCL 1.0.1 (in portable project)
Microsoft.NETCore.UniversalWindowsPlatform 5.1.0
MR.Gestures 1.3.4
Newtonsoft.Json 7.0.1 (in portable project)
Splat 1.6.2 (in portable project)
SQLite.Net.Core-PCL 3.1.1
SQLite.Net-PCL 3.1.1
Xam.Plugins.Settings 2.1.0
Xamarin.Forms 2.3.0.107
Xamarin.Insights 1.12.3
XLabs.Core 2.2.0-pre02
XLabs.Forms 2.2.0-pre02
XLabs.IoC 2.2.0-pre02
XLabs.Platform 2.2.0-pre02
XLabs.Serialization 2.2.0-pre02
And this error occurs The assembly Windows in file C:\Program Files\WindowsApps\<app-name>_1.8.0.0_x64__r1myykanma94r\Windows.winmd has a non-empty exported type reference table. Every Windows Runtime assembly must have an empty exported type reference table.
UPDATE 3
I figured out uninstalling Win2D.uwp and compiling XLabs myself was the way to go.
I had that problem and the resolution was simple: I had a reference to the PCL version Newtonsoft.Json.dll both in my PCLs and in my UWP project. Older portable version (Portable40).
After I updated to the latest version of Newtonsoft.Json.dll (NuGet version 9.0.1) the compilation exception went away.
Keep in mind that when updating I replaced all references to the Newtonsoft libreary i.e.
In my PCLs I now reference the portable version lib\portable-net40+sl5+wp80+win8+wpa81
In my startup project I now reference the Newtonsoft package (my project.json file contents):
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Newtonsoft.Json": "9.0.1",
"Xamarin.Forms": "2.3.2.127"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
which effectively uses the reference to C:\Users\<username>\.nuget\packages\newtonsoft.json\9.0.1\lib\portable-net45+wp80+win8+wpa81.
Published my solution at Xamarin forums quite a while ago and some people say this worked for them as well.
Related
Core Signing + Hardening runtime of .net core app on MAC
I have created a sample .net core worker service app. I want to code-sign the app on MAC, but I get the below error : Your Mach-O executable does not conform to modern Mach-O layout rules. You may be using a third party development product that hasn't been brought up to date, or post-processed your file in unsupported ways. Below are the publish parameters provided while creating the executable: I have added UseAppHost as true in the csproj file. But sill get the same issue <UseAppHost>true</UseAppHost>
seems to be a .net issue with single file, should be fixed in .NET 6 https://github.com/dotnet/runtime/issues/3671
React native windows - app certification kit failed
I'm making simple react-native app. Android version works fine (already on Google Play). Windows version is also working but It cannot pass through certification kit app. I've made release-bundle build according documentation: https://github.com/Microsoft/react-native-windows/blob/master/docs/RunningOnDeviceWindows.md App certification kit return errors: Type ReactNativeWebViewBridge.MessagePostedEventArgs in file ReactNativeWebViewBridge.winmd is not sealed and does not have the ComposableAttribute. Unsealed types must have ComposableAttribute. and API getenv in api-ms-win-crt-environment-l1-1-0.dll is not supported for this application type. ImagePipelineNative.dll calls this API. Built with Visual Studio 2017. Am I missing something? Thanks for any help!
Type ReactNativeWebViewBridge.MessagePostedEventArgs in file ReactNativeWebViewBridge.winmd is not sealed and does not have the ComposableAttribute. Unsealed types must have ComposableAttribute. The error message has explained clearly. You need to use sealed modifier to the MessagePostedEventArgs class in ReactNativeWebViewBridge. If you didn't use sealed, you need to use ComposableAttribute. More information about ComposableAttribute, you could refer to James McNellis's answer in this thread:What is the ComposableAttribute in WinRT? API getenv in api-ms-win-crt-environment-l1-1-0.dll is not supported for this application type. ImagePipelineNative.dll calls this API. This error meant that ImagePipelineNative.dll calls some unsupported APIs in UWP. You need to create an issue in react-native's repository.
Library not loaded, for an internal private framework
I am using Carthage. I have a project named, A-Framework which has a framework inside, named E-Framework, with all code and a header. In A-Framework -> Linked frameworks and Libraries A project a-ios uses framework A-Framework. I got this at run time: dyld: Library not loaded: #rpath/E-Framework.framework. How come that main project a-ios, knows something about the implementation detail of the framework A-Framework ?
Universal Windows Platform/UAP: what is AOT?
I recently created a blank UWP application in Visual Studio 2015, and then tried to add a nuget package to that application. The package installation failed and resulted in the following messasges in the output window... System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot. One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot). System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot. One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot). System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot. One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot). Looking around, I have found references to the "runtimes" within the "project.json"; (mine looks like this)... { "dependencies": { "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0" }, "frameworks": { "uap10.0": {} }, "runtimes": { "win10-arm": {}, "win10-arm-aot": {}, "win10-x86": {}, "win10-x86-aot": {}, "win10-x64": {}, "win10-x64-aot": {} } } My question is this: what is the difference between each "runtime" and the equivalent runtime with "-aot" appended? I have seen some posts that indicate I can delete these runtimes if I want to use a nuget package that does not support them, but I would prefer to only delete them knowing what they are. Note: I do not know if this makes any difference, but the UWP application that I am building is expected to only ever be side-loaded (it is a line of business application). It may however eventually need to be distributed via the Windows Business Store in order to ease updates etc. Thanks.
Runtime is a general term that refers to any library, framework, or platform that your code runs on. The win10-arm and win10-arm-aot runtimes are different platforms. Here is a Wikipedia: Runtime system. Besides, as per Wikipedia Ahead-of-time (AOT): Ahead-of-time (AOT) compilation is the act of compiling a high-level programming language such as C or C++, or an intermediate language such as Java bytecode or .NET Common Intermediate Language (CIL) code, into a native (system-dependent) machine code with the intention of executing the resulting binary file natively. Some programming languages with a managed code runtime that can be compiled to an intermediate language, take advantage of just-in-time (JIT) So I agree with Hans Passant, the AOT compiler is incompatible with System.Reflection.Emit.ILGeneration package. So you can delete these aot runtimes if you want to use this package.
I found the solution to my case. I had several projects in my solution and all of them were using Microsoft.NETCore.UniversalWindowsPlatform V 5.2.3 except for one project. It was using Microsoft.NETCore.UniversalWindowsPlatform V 5.0.0 When I update the 5.0.0 to 5.2.3 all the errors went away. NOTE: You do not need to remove aot tags from the JSON files.
VisualStudio is picking up incorrect assembly version when using project-internal referencing
I have a project which interfaces to external hardware using an API supplied by the manufacturer. Recently a new version of the hardware came out with a slightly modified API. I need to be able to connect to both versions. I copied the 2 versions of the API into 2 folders in the project: Libs +--APIv2 +--APIv4 and added project references to the DLLs in APIv4. My intention is to access the v2 API dynamically using reflection. The strange thing is that, although I add the v4 API from the APIv4 folder as references, it is always the v2 API which is actually referenced. The Path attribute of the reference is the path to the v2 API - /Libs/APIv2. However, if both versions are stored outside of the project and the v4 API is referenced then this does not happen. ie if I reference v4, then v4 is actually referenced. Can anyone explain why this is happening?
I just found out that I can set an attribute on each reference: Specific Version = true. This seems to resolve my problem.