Error when building uwp app in Release mode - c#

I have this app, that builds and runs successfully in Debug mode, on both my local computer and on my Windows Phone device, when trying with the Release mode, I get these 3 errors :
Error Internal compiler error: One or more errors occurred.
The non-generic type 'PInvoke.NTSTATUS.Code__PInvoke_Windows_Core'
cannot be used with type arguments
...obj\x64\Release\ilc\intermediate\Liberte.Windows.Interop\SafeTypes.g.cs 333
The type or namespace name 'Value' could not be found (are you missing
a using directive or an assembly
reference?) ...obj\x64\Release\ilc\intermediate\Liberte.Windows.Interop\SafeTypes.g.cs 333
The actual code where the two last errors are detected is an auto generated code under a file named SafeTypes.g.cs and the line where the errors is raised is :
namespace PInvoke
{
[global::System.Runtime.InteropServices.McgRedirectedType("PInvoke.NTSTATUS,PInvoke.Windows.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a")]
public unsafe partial struct NTSTATUS__PInvoke_Windows_Core
{
public global::PInvoke.NTSTATUS.Code__PInvoke_Windows_Core <Value>k__BackingField;
}
}
I don't have any idea what does this mean, nor what should I do, any explanation and solution to this ?
Update :
Tried to Close VS, then Delete the Obj and the Bin content, rebuild again, but stuill have the same error.
I should mention maybe that I have reference to 2 other projects, one of them is a PCL project that uses PCLCrypto library, and the other one is a Universal App library that uses EntityFramework 7 pre-release with sqlight.
Update 2:
I tried to disable compilation with .Net native just to see what goes on, the release build succeeds, but the App crashes and quits just after startup.
Update 3:
I just discovered that the PCLCrypto library that I use in one of the two project I'm referencing, references two libs that are causing the problem, and they are mentioned in the errors above, I found this out when trying to uninstall the library to see if it is the cause of the problem :
I tried to rollback to a previous stable version, compiled in Debug mode, everything worked perfectly, when I try again Release mode with .Net native, I encounter a new problem : Out of memory.

Concerning Update 3, it seems to be a bug with .NET Native tool chain, I opened an issue on PCLCrypto repo that was moved to corert repo

Related

Xamarin iOS Linker Issue

I have an application that has an android and ios project with shared code. The android application works perfectly and uses the SDK Only linker. I also have a Linker file to enforce linker not removing used functions - Which is a fairly large file and I've also tried adding a bunch of preserve attributes. The same situation in the iOS project, however, doing the same thing doesn't work. It removes something from EF and throws this exception:
"The type initializer for 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions' threw an exception. ---> System.InvalidOperationException"
This whole codebase works perfectly fine without the linking. I've added a bunch of mtouch arguments to try and skip it but that ain't working either.
--linkskip=Microsoft.EntityFrameworkCore
--linkskip=Microsoft.EntityFrameworkCore.Design
--linkskip=Microsoft.EntityFrameworkCore.Sqlite
--linkskip=Microsoft.EntityFrameworkCore.Tools
--linkskip=Interactive.Async
--linkskip=Remotion.Linq
--linkskip=System.Data
--linkskip=System.Collections.Immutable
--linkskip=System.Diagnostics.DiagnosticSource
--linkskip=Microsoft.Extensions.Logging
--linkskip=System.Interactive.Async
--linkskip=Microsoft.EntityFrameworkCore.Abstractions
--linkskip=Microsoft.Extensions.DependencyInjection
--linkskip=Microsoft.Extensions.Caching.Memory
--linkskip=System.ComponentModel.Annotations
I'm about to add every DLL in the NuGet repository which will make the Linker useless. Is this a bug for the iOS Linker or what am I missing here? I've read the documentation https://learn.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows and searched everywhere on the internet and nothing comes up. Any help is appreciated.
Thanks,
If you are using "Link SDK assemblies only" option on iOS project, then all of those --linkskip arguments won't do anything as only the SDK assemblies are being linked. So the EntityFrameworkCore might be using something that is being linked away that is in the Xamarin.iOS SDK assemblies. System.Linq is part of the SDK and adds extension methods for many database types.
So I think you may be hitting this issue: https://github.com/xamarin/xamarin-macios/issues/3394
If so, try putting:
[assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)]
in the Main.cs file of the iOS project outside of the namespace, e.g.:
using UIKit;
[assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)]
namespace
{
...
}

Azure Function referencing mixed-mode assembly

TL;DR: Is it possible to use mixed-mode assemblies in Azure Functions?
Details: I have an in-house mixed-mode assembly that I'm trying to use in an Azure Function. When I try to build, I get the following error:
------ Build started: Project: AzureDemo, Configuration: Debug x64 ------
AzureDemo -> C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll
C:\Users\hugh\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'file:///C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Done building project "AzureDemo.csproj" -- FAILED.
For clarity, the in-house library is x64 and my demo project is also x64, so it's not an x86/x64 problem.
Also, when I take the code out of the Azure Function project and put it in a plain old .NET Core 2.0 project, it builds just fine. edit: it builds fine, but it still doesn't run (System.EntryPointNotFoundException: A library name must be specified in a DllImport attribute applied to non-IJW methods.). So I may be in deeper water than I thought.
I'm kind of afraid Azure Functions won't work with mixed-mode assemblies... but I haven't found any definitive statement to that effect.
I'm also a little concerned that the fact that it's using netstandard1.0 might have something to do with it.
The error is happening at build time when the SDK launches the build task to generate the build artifacts/function metadata.
I've opened this issue with the details to track the bug: https://github.com/Azure/azure-functions-vs-build-sdk/issues/131
Actual x64 CLI releases would also be required for successful local testing, and this is tracked here: https://github.com/Azure/azure-functions-cli/issues/117

Xamarin App builds and runs on simulator, but on real phone I get Assembly Failure

I am working on a Xamarin based mobile app. It has previously deployed to an iPhone, and is currently working on the simulator. However, when I try to Debug on my iPhone, I get:
Error MT2002: Failed to resolve assembly: 'PCLStorage.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64' (MT2002) (My_App.iOS)
PCLStorage is installed and up to date in my iOS and Core projects, although neither have any references to the package. It was installed when I added the AWS Core SDK. How do I resolve this error, I assume that is what is stopping the debug on iPhone?
Edit: (based on Answer below)
If I disable the linker in my build settings, I get the error:
My_App/iOS/MTOUCH: Error MT3001: Could not AOT the assembly 'My_App/iOS/obj/iPhone/Debug/build-iphone4.1-9.2.1/mtouch-cache/Build/AWSSDK.Core.dll' (MT3001) (My_App.iOS)
I would really appreciate some suggestions as I haven't made much headroom with this...
Try disabling "Linker" in the build options for Device builds. It's possible that if you are not directly referencing the library, the linker is stripping it out, causing it to fail at runtime.
I just had the same problem after switching from the simulator to an actual device
Fortunately, I've gotten the error only in 3 pages...
Fix was to remove the assembly attribute from the XAML:
From
xmlns:viewModels="clr-namespace:XXX.ViewModels;assembly=XXX"
To
xmlns:viewModels="clr-namespace:XXX.ViewModels"

SimpleITK Windows Universal App - does not build in release, strange behaviour in debugging and TypeLoadException

TL;DR version: Could not load type 'System.Runtime.InteropServices.HandleRef while trying to use SimpleITK on Universal Windows App.
So, right now I have to make simple school project using SimpleITK, and, I got interested in new Universal Windows Applications. I am using Visual Studio 2015 Enterprise.
So, I created a sample project, added references to SimpleITKManaged, copy&pasted SimpleITKNative to obj/Debug catalog and tried to do some tutorials. However, I learned that mixing two new technologies together may be a bad idea.
The ITK libraries I use seem not to work with Universal Windows App. After putting this snippet anywhere in the code, I can not get to debug the method. Code is not hitting breakpoint at the beggining of the method. What is inside is not important, as any type from SimpleITK is causing code to fail.
private void TestMethod()
{//breakpoint here
ImageFileReader reader = new ImageFileReader();
reader.SetFileName(FileName);
var image = reader.Execute();
}
The exception seems to be thrown before code gets to method, probably at level of XAML. I tried first implementing a call as ICommand, then as event handler in the code behind, with no differences. The exception is also not too helpful:
Could not load type 'System.Runtime.InteropServices.HandleRef' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
Neither is StackTrace:
at Pomwjo.Universal.MainPage.ButtonBase_OnClick(Object sender, RoutedEventArgs e)
The same libraries work well in WPF. I tried both x64 and x86 libraries, with the same problem. The build target and library architecture are matching. I'm using SimpleITK C# x86 wrapper 0.9.0, compiled with .NET v2.0.50727, using ITK 4.7.2. I got them pre-built from Sourceforge. Just after that, I found a 0.9.1 version, which I downloaded and tried to use it, to no avail.
Next step was ok, I'm a pro programmer - I'll build it myself!. I will spare describing what it is to build a huge library, let's just say it didn't work either.
Any ideas, how to fix this problem?
EDIT 1
I just realized, that if code is unreachable, it doesn't complain. Well, at least that is working as expected. But, what is even stranger, this snippet fails only if condition is met:
if (new Random().Next(1, 10)%2 == 0)
WrapperMethod(); //inside is snippet from above.
else return;
Also, when building in release, I get this error:
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x64\ilc\IlcInternals.targets(791,7): error : MCG0024: MCG0024:UnresolvableTypeReference Unresolvable type reference 'System.Runtime.InteropServices.HandleRef' in 'Assembly(Name=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)' found. Check the references in your build system. A reference is either missing or an assembly is missing an expected type.
When this question was first written, it was impossible to use simpleITK in Universal Apps because it lacked some of classes required for it to work - including System.Runtime.InteropServices.HandleRef.
Also, because all apps are run in sandbox, my guess (educated, but still guess) is that it is downright impossible to use native C++ code which is used by SimpleITK. This link describes a way to import native code into app, however this would require quite a bit of tinkering around ITK libraries itself - which was not a point in my project.

Why am I getting the following error when compiling this assembly?

I'm attempting to use the following command line command to compile an assembly of the code from my project:
C:/"Program Files"/Unity/Editor/Data/Mono/bin/gmcs
-target:library -out:C:/Users/Austin/Desktop/PixelExpanse.dll
-recurse:C:/Users/Austin/Desktop/Projects/Repos/trunk/PixelExpanse/SpaceColonyRefactor/Assets/Source/*.cs
-d:RUNTIME -r:C:/"Program Files"/Unity/Editor/Data/Managed/UnityEngine.dll
As you can see, I am, I believe, correctly referencing the UnityEngine.dll.
The code that would be compiled contains references to UnityEngine.UI and UnityEngine.EventSystems. But when I run the above command, I get the following compile error:
error CS0234: The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine'. Are you missing an assembly reference?
From what I have been able to find through googling, it SEEMS like an error people were getting when using a pre-4.6 assembly, because thats when EventSystems and UI were both introduced. But I don't know how I could be missing that in the dll I'm referencing as Unity 5 is the only version that has ever touched this computer.
As a side note, I have posted this question to Unity Answers and have yet to receive a response. I expect it's because assembly compilation is beyond the scope of what most users there choose to undertake. Hence my asking it here.
The namespace UnityEngine.EventSystems actually appears in UnityEngine.UI.dll and not UnityEngine.dll so it seems you need to reference the former too when compiling manually from the command-line. Unity projects have this by default (see below).
This is verified by opening up the assembly in your reflector tool of choice, here I am using JetBrains dotPeek:
This is how my test project appears with default Unity references. Note that by default a reference to UnityEngine.UI already appears in the Unity-created project:
When I built my Windnows desktop app via Unity, the above dlls appeared in:
<drive>:<projectOutFolder>\<projectName>_Data\Managed
You can try:
right click on "project panel", and after "Reimport All".
It's can be happen due to switch between platforms, e.g. IOS, or Desktop.. thus, folrders are deleted by became unecessary..
Solve for me: Unity 5.2, Win 7, 32bits;
Good luck!
I checked the UnityEngine.dll and the Eventsystems/UI namespace is not included. Despite, there is a dll in Unity5\Editor\Data\UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll which includes these namespaces.
For mac, it's /Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll.

Categories