Application-internal exception in Windows.UI.Xaml.dll - c#

I'm working on a Windows 10 Store Windows Universal app using Visual Studio 2015 Community, c#, and XAML. It is decompressing a compressed file and displaying images found therein.
The build provides 0 warnings.
The debug version runs fine regardless of input file size.
The release version runs fine with typical input file sizes.
For large input file sizes (~100 1 megapixel images), the release build crashes consistently with 'Unhandled exception at 0x55E9A305 (Windows.UI.Xaml.dll) in appname.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x127DC468, 0x00000005).'
The crash occurs when the user tries to display the second image. All decompression is complete and all the bitmaps have been created by this time.
I've fiddled with the Build settings and narrowed down the difference to the option 'Compile with .NET Native Tool chain'. If that option is checked, the application crashes. If that option is unchecked, the application runs fine.
All told, the application is using about 400 MB of heap so although not small it isn't near the capacity of the machine.
"So uncheck the option!", I hear you cry. Unchecking the box leads to the certification failure shown below:
FAILED
Supported APIs
• Error Found: The supported APIs test detected the following errors:
-API OpenSemaphore in api-ms-win-core-synch-l1-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
-API CreateSemaphore in api-ms-win-core-kernel32-legacy-l1-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
-API ExecuteAssembly in uwphost.dll is not supported for this application type. StupidTest.exe calls this API.
-API DllGetActivationFactory in uwphost.dll is not supported for this application type. StupidTest.exe has an export that forwards to this API.
An empty project suffers the same failure if Compile .Net Native tool chain is not selected.
So my questions:
Must Universal Apps use Compile .Net Native tool chain?
Is there any documentation on the meanings of the parameters in the internal exception or somewhere else I can turn to troubleshoot?
In short, any advice on getting out the "It doesn't work if selected, but you must select it to get certified" dilemma I find myself in?

I struggled with this issue also for the past few days, and I've found the answer!
So if you haven't updated Visual Studio 2015 to Update 1, do it. Because this error is a bug in the compiler and after the update you will be able to build the project with the Compile .Net Native tool chain option selected.
And yes, those four errors that the WACK tool picks up, is because of compiling your project without checking the .Net Native tool chain option in the Build menu of the Package.appxmanifest file.

Related

Fatal error. Internal CLR error. (0x80131506) on String.Format() [duplicate]

The exception code C0000005 is thrown from mscorwks.dll when the application is run on Windows Server 2008 R2 launched using test complete. Other platforms (Windows XP, Server 2003 R2, Windows 7 32-bit and 64-bit) do not present this exception.
The event log from a single execution has many of the following event with event ID 1023 raised by the .NET Runtime:
.NET Runtime version 2.0.50727.4952 - Fatal Execution Engine Error (7383851A) (80131506)
The application itself makes use of a SOAP interface generated by Visual Studio from a WSDL file, a COM object with an embedded interop, and is targeting .NET 4.
sfc /scannow was run and found no problems with system files on the affected system.
What troubleshooting can be done to identify a solution?
Fatal Engine Execution Error and an access violation are both symptoms of the same problem. FEEE is raised when the .NET garbage collector detects that the internal structure of the garbage collected heap is destroyed. An access violation is a hardware exception, raised by the processor when it is asked to access memory with an invalid address. A common cause of an AV is heap corruption.
These kind of mishaps are very commonly caused by unmanaged code. It is also quite common for unmanaged code to have latent memory management bugs that can go unnoticed for a long time. The kind of damage the bug can do tends to be quite random. Just running it on another operating system which has a different memory allocation pattern can be enough to trigger the bomb.
You have an excellent candidate for the source of the trouble. You'll need to work with the COM server vendor or author to chase the bug.
A 0xC0000005 is an exception code wrapping a Win32 error which means "Access Denied." Given that you are using COM interop and are getting an ExecutionEngineException (in COM, COR_E_EXECUTIONENGINE; 0x80131506), my guess is that either it's a NULL pointer in the COM component or a faulty ComImport directive in your .NET code.
This error is caused by flaws in the way that TestComplete 7 interacts with the heap in mixed managed/unmanaged applications. Instead of using the TestedApp.Run method using the following block of code, modified for you choice of scripting language, presented in VBScript:
Dim oScript, command
Set oScript = CreateObject("WScript.Shell")
command = "%comspec% /c " & PATH_TO_EXE & " " & Args
oScript.Run command, 10, True
The relevant MSDN article is Run Method (Windows Script Host).
TestComplete 7 (including the latest update 7.52) supports .NET Framework 4 only up to version .NET 4 Beta 2. It does not support the release version of the Framework, so this may be the reason of the problem.
Try building the application targeting .NET 2.0. This should resolve the problem.
To test .NET 4 applications, you will need to use TestComplete 8.

AppCrash in mscorlib.dll: Unable to cast object of type 'System.Threading.ManualResetEvent' to type 'System.Threading._ThreadPoolWaitOrTimerCallback'

My application randomly crashes on my target machines with an .net failure. In mscorelib.dll there seems to be a System.InvalidCastException.
The error occures in:
System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object, Boolean)
and the reason is:
Unable to cast object of type 'System.Threading.ManualResetEvent' to type 'System.Threading._ThreadPoolWaitOrTimerCallback'.`
The Application runs multiple times on the target machine (win7 x64).
The Application is a x86 application.
There have never been issues before I was forced to compile the Application to the .net 4.6+ target framework. But I need to go up to at least 4.6 due to other dependencies now.
I thought it could be a issue with garbage collection and set <gcConcurrent enabled="false"/>. But this did not help.
I tried to debug the miniDumps with WinDbg. But I was not successful to find a way to track the Issue down to a specific line of code or a method in my code. I don't think it is a .net issue, but I have no clue how to find the corresponding line in my code.
Edit on request:
Former .net target framework: 4.5.1
The application crashes randomly, could be after more than 24h
I'm not able to figure out in which part of my code the application crashes
The same application runs independent parallel on the same machine. Sometimes randomly one or two instances crash.

Visual Studio C# zoneidentifier.cxx The system cannot find the file specified && Rejecting native image because native image dependency

Visual Studio 2017 Console Output shows me
onecoreuap\inetcore\urlmon\zones\zoneidentifier.cxx(359)\urlmon.dll!6F1D6037: (caller: 6F1D6F68) ReturnHr(1) tid(24e0) 80070002 cannot find the file specified.
onecoreuap\inetcore\urlmon\zones\zoneidentifier.cxx(359)\urlmon.dll!6F1D6037: (caller: 6F1D6F68) ReturnHr(2) tid(24e0) 80070002 cannot find the file specified.
CLR:(C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll) Rejecting native image because native image dependency C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll had a different identity than expected
CLR:(C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll) Rejecting native image because native image dependency C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll had a different identity than expected
IMGSF01-DLL_PROCESS_ATTACHC:\WINDOWS\system32\ImgsfProcPolicyForExe.xmlException thrown at 0x76E608C2 (KernelBase.dll) in application.exe: 0x000006BA: RPC Server Unavailable
I want to know what those outputs are meaning and how to solve it.
Currently application looks working fine. However, I should make it sure before release application to market.
My application depends on .NET Framework 4.5.2 and Winform.

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.

.NET native windows store release

I have problem with release version of my application. After retarget windows store app to universal windows platform project i can't run application in release mode with Compile with .NET Native tool chain option checked.
I get an error:
Exception thrown: System.Reflection.MissingRuntimeArtifactException in System.Private.Reflection.Core.dll
Additional information: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: System.Linq.Enumerable.Distinct<System.Char>(System.Collections.Generic.IEnumerable<System.Char>)
For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868
When i disable Compile with .NET Native tool chain application is working and doesn't throw a exception.
Generally this is solution, but in Windows App Certification Kit i get failed result with errors (Test Supported API):
·API ExecuteAssembly in uwphost.dll is not supported for this application type. App.exe calls this API.
·API DllGetActivationFactory in uwphost.dll is not supported for this application type. App.exe has an export that forwards to this API.
·API OpenSemaphore in ap-ms-win-core-synch-11-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
·API CreateSemaphore in api-ms-win-core-kernel32-legacy-11-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
Someone can help?
The .NET Native runtime doesn't include a JIT compiler. As a result, all necessary native code must be generated in advance. A set of heuristics is used to determine what code should be generated, but these heuristics cannot cover all possible metaprogramming scenarios. Therefore, you must provide hints for these metaprogramming scenarios by using runtime directives. If the necessary metadata or implementation code is not available at runtime, your app throws a MissingMetadataException, MissingRuntimeArtifactException, or MissingInteropDataException exception. Two troubleshooters are available that will generate the appropriate entry for your runtime directives file that eliminates the exception:
The MissingMetadataException troubleshooter for types.
The MissingMetadataException troubleshooter for methods.
See here: https://msdn.microsoft.com/en-us/Library/dn600640%28v=vs.110%29.aspx

Categories