Archiving Xamarin Android App gives error XABLD7019 - xamarin

VS 2019 Version 16.7.1, Xamarin Forms v4.8.0.1269
Worked previously, but archiving the Android App now fails (iOS OK). I have updated the Android SDK.
The error is (logging set to diagnostic):
XABLD7019: System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Java.Interop.dll.lz4' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Xamarin.Android.Tasks.AssemblyCompression.Compress(AssemblyData data)
at Xamarin.Android.Tasks.BuildApk.<AddAssemblies>g__CompressAssembly|138_1(ITaskItem assembly, <>c__DisplayClass138_0& )
at Xamarin.Android.Tasks.BuildApk.AddAssemblies(ZipArchiveEx apk, Boolean debug, Boolean compress, IDictionary`2 compressedAssembliesInfo)
at Xamarin.Android.Tasks.BuildApk.ExecuteWithAbi(String[] supportedAbis, String apkInputPath, String apkOutputPath, Boolean debug, Boolean compress, IDictionary`2 compressedAssembliesInfo)
at Xamarin.Android.Tasks.BuildApk.RunTask()
at Xamarin.Android.Tasks.AndroidTask.Execute()
There is a file in that folder called 'Java.Interop.dll', but not one called 'Java.Interop.dll.lz4'.
Does anyone have any ideas as to what may be causing this?

UPDATE: upgrading to visual studio 16.7.5 fixes this.
Updating to Visual Studio "16.8.0 Preview 1" doesn't fix this bug.
Workarounds:
add <AndroidEnableAssemblyCompression>false</AndroidEnableAssemblyCompression> to the release section of your csproj. (I've confirmed this one works) But it may result in increased apk sizes. (UPDATE: doesn't appear to increase the apk size)
Enable project Linking. (unfortunately for some projects this is very hard to get working)
Run Visual Studio as admin. (I've confirmed this works on the Preview install, but wasn't prepared to do this on normal install)
Add user modify priviligies to
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\
(This is kind of like (3) but less extreme. (I've confirmed this works))

I had this issue when preparing my android app for archiving in VS19 and found that setting the linking to 'SDKs assemblies only' resolved the issue for me, hope this helps someone.

Related

System.IO.FileNotFoundException: Could not load assembly "AppName" after update xamarin forms

I can't rebuild the project and I'm getting this exception after updating to latest Xamarin Forms 3.4.0.1008975 , if I downgrade it to 3.1.0.583944 or lower the exception will gone and I can build successfully.
I've tried to update VS and clean - close - reopen but the problem still there , I also tried to move the project to C:/ but no luck .
Error The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'SouqAlData, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'SouqAlData.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() SouqAlData.Android
My understanding of the situation tells me that you do not have the latest version of Xamarin which comes along with Visual Studio 15.9.xx.
And hence when you update your Xamarin Forms package to the latest version of that is available it sees a discrepancy in between the versions and hence might be throwing this. One more reason could be that when you update your Xamarin Forms package, somehow the path for your SouqAlData.dll is lost by VS and hence you get this error. What I would suggest you do in case two is that you provide the proper path for your .dll again to VS and see if that helps you build the project.
You can give the path as follows:
Remove the existing reference to the .dll
In your project go to References>Add Reference>Browse then give it the .dll path from your solution directory.
Update:
From recent Xamarin forms update code behind doesn't support Task return type as signatures for event handlers.
So Replacing the Task with Void return type did the trick. Reference
This error happens when you have another error in the solution in your case in xaml file check for you xaml code for a mismatch code or events. In my case i found "-->" in the xaml file and it was the problem.

Adding .png File to Xamarin IOS project Crashes Build

I am working on a Xamarin IOS project and just created a .png file that I want to display in the app. When I add the image to the Resources folder the app no longer builds and displays the following error:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(3,3): Error: System.IO.FileNotFoundException: /Users/davidshepard/Projects/NewEPA/NewEPA/obj/iPhoneSimulator/Debug/device-builds/ipad6.12-11.0/optimized/Pres0.png does not exist
File name: '/Users/davidshepard/Projects/NewEPA/NewEPA/obj/iPhoneSimulator/Debug/device-builds/ipad6.12-11.0/optimized/Pres0.png'
at System.IO.File.Copy (System.String sourceFileName, System.String destFileName, System.Boolean overwrite) [0x00193] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/File.cs:111
at Xamarin.MacDev.Tasks.SmartCopyTaskBase.CopyFile (System.String source, System.String target, System.String targetItemSpec) [0x00030] in <3718405664a748fa8803db38a9584ea4>:0
at Xamarin.MacDev.Tasks.SmartCopyTaskBase.Execute () [0x0013d] in <3718405664a748fa8803db38a9584ea4>:0 (NewEPA)
I verified that the file was being added to the .csproj file and I still get this error even when I do reference this image anywhere in my code other than the .csproj
Another interesting piece of information is that Images that I added before upgrading to the newest version of Xamarin.IOS and Visual Studio for Mac 2017 work just fine even if I remove and readd the m to the project.
Any suggestions as to how I can resolve this issue would be greatly appreciated!
Additional Info: iPad only app. IOS 11.
So after a scratching my head for a few days, I figured out what went wrong. When I was uploading the file to Visual studio, it was becoming corrupt and unreadable. I had to reinstall visual studio to fix the issue and now it's working fine. If you experience the same problem, it is most likely due to the file being corrupt. Hope this helps someone in need!

Visual Studio 2015 fail to load package because Microsoft.VisualStudio.Shell.15.0 fail to load

I've built a Visual Studio extension for Visual Studio 2015 and 2017. I've developed it with 2017 and everything works great on 2017.
When I install it on VS 2015 I get an error message saying it failed to load my package. In the visual studio ActivityLog.xml file I see the following error.
How can I enable both VS 2015 and 2017 to run the extension?
CreateInstance failed for package [MainWindowPackage]
Source: 'mscorlib'
Description: Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
According to the error message, your extension dependency on Microsoft.VisualStudio.Shell.15.0, which is a VS 2017 assembly. So it is not contained in your VS 2015.
If you want your extension supports multiple versions of Visual Studio, you need to let your VSPackage to using only the features of the earliest version of Visual Studio that you support and program your VSPackage to adapt to the version of Visual Studio in which it is running. You could read this document: https://learn.microsoft.com/en-us/visualstudio/extensibility/choosing-between-shared-and-versioned-vspackages
And you also could reference the document that Supporting Multiple Versions of Visual Studio.
The custom installation path is "C:\Users\UserName\AppData\Local\Microsoft\VisualStudio\14.0\Extensions\". Please check your extension path to make sure the Microsoft.VisualStudio.Shell.15.0 is installed.
You should reference Microsoft.VisualStudio.Shell.14.0 and other assemblies from VS 2015 in your extension to support both VS 2015/2017.

"CompileXaml" task failed unexpectedly in Visual Studio while develop Xamarin project

I opened a Xamarin cross platform sample Project in Visual studio 2013 and When I build, it gives this error:-
This question is also same but no one reply any answer.
Error 2 The "CompileXaml" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'XamlServicesWP, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'XamlServicesWP, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Server stack trace:
at Microsoft.Silverlight.Build.Tasks.CompileXaml.GenerateCode(ITaskItem item, Boolean isApplication)
at Microsoft.Silverlight.Build.Tasks.CompileXaml.Execute()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Finally , I got solution for this. I upgrade my Visual Studio from Update 2 to Update 4. When you Build your project it gives and error about Hyper - V Network adapter. To Solve that, allow to change in Hyper -V Network Adapter settings by click on "Retry" button in prompt. ( You can also upgrade Window phone SDK to 8.1 for better experience. It is optional not necessary to solve this error.)
I worked around this problem by going back to Visual Studio 2019, rather than sticking with Visual Studio 2022. It seems 2022 still has a few issues.

Word 2010 addin does not load, vsto 2010

Our development machine is 64 bit hardware running Windows 7 Professional N (64 bit), 64 bit Office Professional 2010 and Visual Studio Professional 2010.
We created a Word 2010 (Application Level Add-In) using .NET Framework 4, Ribbons and Windows installer targeting Office 2010. We followed everything from the official MSDN online tutorials to the dot several times. For our installer we selected .NET 4 client profile and Windows installer 3.1 as prerequisites, since Office 2010 has VSTO 4.0 runtime installed and .NET framework 4 has no-PIA functionality. In launch conditions we checked for Office 2010 Shared PIA and Word 2010 PIA availability using the appropriate component ids. Additionally we checked for VSTO runtime availability as is laid out in the MSDN article.
Our Add-In loads and executes with full functionality from ONLY within Visual Studio debug (F5). Building the setup project creates the Windows installer (msi). Installing it installs the Add-In on the machine without any errors. However after installing the Add-In when we try to open any Word 2010 document, we are witnessing the following behavior:
We try to open any Microsoft Word 2010 document, Word 2010 startup screen shows up and we can see our Add-In being loaded "Loading [Our] Add-In" but then Word 2010 does not open. The startup screen disappears and no error message is displayed.
Opening the word document for the second time just fires up this message (no word 2010 startup screen this time):
Word experienced a serious problem with the '[Our] word addin' add-in. If you have seen this message multiple times, you should disable this add-in and check to see if an update is available. Do you want to disable this add-in?'
Clicking on No, briefly fires up the startup screen of Microsoft Word 2010 and then it stops loading again (disappears). Clicking on Yes, opens Word 2010 with the [Our] add in disabled. Verified by clicking File-Options-AddIns. Looked under Disabled Application Add-Ins
Setting VSTO_SUPPRESSDISPLAYALERTS=0 and VSTO_LOGALERTS=1 was of no use either. We checked our Temp directory, there were no logs.
Since the above method did not work I downloaded the sample project from this link named 'Deploying a VSTO 2010 solution for Office 2007/2010 using Windows Installer' and used the appropriate project found under Office Development - Setup and Deployment Projects Samples\FX40\AddIn Deployment\All User Install for 64-bit Office.
Initially I tested the solution to correctly load the demo Excel 2010 Add-In project by creating and running the installer (msi) Then we added our Word AddIn project to the solution file by file and built it correctly (CTRL+SHIFT+B). It even ran from Visual Studio debug (F5) correctly. Then we reconfigured the existing set up project to delete the demo Excel project and load our word Add-In's primary output, [OurAdd-In].vsto and [OurAdd-In].dll.manifest files. We refreshed project dependencies and took appropriate steps to exclude relevant files. We kept the registry checks intact and added launch conditions to check for Word 2010 PIA.
The installer built successfully and installed without errors but unfortunately we witnessed the exact same behavior of Word 2010 as described previously.
We also tried debugging using Windows event logging. I found this event with event id 4096:
************** Exception Text **************
Microsoft.VisualStudio.Tools.Applications.Deployment.FrameworkVersionMismatchException: <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.0" profile="Client" supportedRuntime="4.0.30319" />
<framework targetVersion="4.0" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
We need to create an installer for our Word Add-In for both 32-bit and 64-bit Word 2010.
I've researched further and this is what I've found.
I used AddInSpy to investigate further and this is the debug information I get ...
<addIn>
<Item>1</Item>
<Host>Word</Host>
<Running>true</Running>
<Loaded>false</Loaded>
<Type>VSTO</Type>
<FriendlyName>[OURADDIN]WordAddIn</FriendlyName>
<ProgID>[OURADDIN].WordAddIn</ProgID>
<CLSID>n/a</CLSID>
<Manifest>C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN]WordAddIn.vsto|vstolocal</Manifest>
<DllPath>C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN]WordAddIn.dll</DllPath>
<LoadBehavior>3</LoadBehavior>
<RegHive>HKCU</RegHive>
<AssemblyName>?</AssemblyName>
<CLR_version>?</CLR_version>
<Exposed>false</Exposed>
<Interfaces>?</Interfaces>
<FormRegions>n/a</FormRegions>
<VSTOR>2008</VSTOR>
<Installed>?</Installed>
<PubVer>n/a</PubVer>
<Status>Alert</Status>
<StatusDescription>Add-in DLL path is not found. System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at AddInSpy.AssemblyScanner.GetAssemblyInfo(String fileName, String hostName, Boolean isVstoAddIn)
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Users\Interance\Downloads\AddInSpy\AddInSpy.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Interance-PC\Interance
LOG: Where-ref bind. Location = C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll
LOG: Appbase = file:///C:/Users/Interance/Downloads/AddInSpy/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This is an inspection only bind.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/[OURADDIN]Setup2010/[OURADDIN]AddIn.dll.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.
</StatusDescription>
</addIn>
I believe what is interesting above are the following lines
This assembly is built by a runtime newer than the currently loaded
runtime and cannot be loaded...
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
In my understanding Word 2010 is trying to load my Add-In using Assembly Manager and Machine Configuration File referencing F/W version v2.0.50727 when it should be referencing \Framework64\v4.0.30319\ since I've built my Add-In using .NET 4. As a consequence is the error message 'This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded...'
I think this might be the source. Any thoughts why this might be happening and how to resolve it?
Hmm... I think I should have mentioned this earlier but I'm using open xml 2 sdk to create/read word files in my Word 2010 Add-In with .NET f/w 4. I've followed the documentation provided here. If you scroll down that page you will find in the section Introducing Open XML SDK Format Architecture subsection system support layer that it supports .NET f/w 3.5 and currently the Open XML Format SDK is based on Standard Ecma-376.
Furthermore, after couple of hours of squinting and reading lots of articles such as Chris Rae's detailed article where he states that Office 2010 uses another standard, ISO/IEC 29500, as its default file format while Office 2007 supports ECMA-376. Further it states that:
ISO/IEC 29500 is a direct descendant of ECMA-376. It's so direct a descendant, in fact, that ECMA-376 2nd edition is identical to ISO/IEC 29500.
I found that Open XML SDK Format Architecture system support layer supports .NET f/w 3.5 and currently the Open XML Format SDK 2 is based on Standard Ecma-376.
Link for Reference
Therefore I'm just wondering if Open XML SDK 2 is the source of my problem? Since ISO/IEC 29500 is descendant of ECMA-376, can I use Open XML SDK 2 to create/modify word 2010 documents in my code?
Is that why the assembly manager and machine configuration file are loading from framework\v2.0.50727\ and not from \Framework64\v4.0.30319\?
Open XML SDK 2 was the cause, I avoided Open XML SDK 2 and my AddIn works perfectly now. Rebuilt my project from scratch using Microsoft Interop to read/write Microsoft Office 2010 documents.
Issue is that there is not much documentation around for developers to read. I've done the grunt work reading articles and figuring out the problem myself.
Hopefully others would not have to face the same ordeal.
See maybe the following link will help... How to create a custom install program.
It helped me, and I had a somewhat similar scenario (a Word 2010 Addin + Open XML SDK 2.0 - deployed on machine running from Windows XP Service Pack 3 32 bit to Windows 7 Professional 64 bit).
Hope it helps you.

Resources