Error MT2001: Could not link assemblies. Reason: Error while processing references - xamarin

I'm getting this error trying to build a Xamarin.iOS project referencing a .NET Standard 2.0 library.
None of the MT2001 issues online seem to have this specific "Error while processing references" reason, so I'm at a loss as to how to diagnose this. I've tweaked and fiddled about as much as any one person can and stay sane, but I'm really in the dark.
Can anyone out there point me in a direction?

Adding -v -v -v -v to "Additional mtouch arguments" in the project iOS Build settings will help diagnose the issue. After that, you can search the build output for MT2001 and view the inner exceptions. Obviously, each project may differ as to what assembly causes the linker to fail. You may need to add, remove or fix your references based on the output.
For example, I was trying to use SignalR from AspNetCore 2.1, which has a dependency on System.Threading.Tasks.Extensions 4.5.1 in my project, which it seems Mono does not yet support. Mono does not provide its own version of the assembly yet, so when mtouch goes to link the assembly, it's unable to do so and throws an exception:
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Removing all references to this assembly (and therefore the whole feauture in my case) allowed the build and linking to succeed.

I've found that I get this when using a Xamarin library that is dependent on System.Reactive 4.1.0. There's a bug in there associated with System.Threading.Tasks.Extensions, and since it is a library I'm writing, I had to roll back to System.Reactive 4.0.0.

For me the error is as follows.
one of the package is mentioned in package.config file but it was not available in packages. So i added the missing package from nuget and the app works fine

Related

UnityPlayer_UAP_ARM64_release_il2cpp.pdb not loaded

I've installed several packages in a Unity (2020) app I'm building. Namely: World Locking Tools, MRTK, PUN2. World Locking Tools provides some examples that are built with assemblies defining scripting symbols that any derived files I want to build would need access to. I'd like to create my own version of certain files from one of these examples. To do this and have access to the scripting symbols in one of those examples, I created an assembly reference to reference the assembly for that example code within World Locking Tools package installed in my project space. In so doing, I kept running into the common "...not found, are you missing an assembly reference" issue, which ultimately led me to creating assembly references for many of the assemblies provided by the various packages I needed to use (not just the particular example code I initially wanted to modify). Once my project finally built successfully in unity, I then tried to upload to a Hololens 2 headset in Visual Studio. This provided the error in the title of this post. Coincidentally, the app also appears to fail to start on the headset. Before I tried to alter my codebase with modified versions of files from that World Locking Tools example and with assembly references, the code would successfully build in Unity and successfully deploy to the Hololens 2 headset.
Does the behavior and missing .pdb error I describe mean that I'm missing assembly references for yet other packages even though Unity successfully builds the project?
This is my first foray into using assemblies so be please be gentle :)
For the .pdb message, that one is ignorable since will not have that symbol available. However, the app not starting is definitely likely due to a missing component or loading issue. When ran in debugger, may get a better idea on what is missing or from a debugger log in Unity.

Xamarin Android binding duplicate packages causing "Program type already present" build error

I am trying to build Xamarin Android binding libraries for two different RFID hand held scanner SDKs (from two different companies), and then reference them in a Xamarin.Android project. So the end goal is to have one application that can run on Device A or Device B and depending on the device manufacturer it will use a different implementation of a "scanner" interface. If I try to reference both of the resulting dlls from the Xamarin.Android project, then I get the following error:
Program type already present: com.hsm.barcode.DecodeOptions
Looking in the jars using JD-GUI as suggested in the Microsoft Docs I can see the problem is that both of the jars have a com.hsm.barcode package:
What is the best way to workaround this issue?
Note that if I use only one of the dlls then I have no issues.
What I have tried:
Using a single Xamarin Android binding library project for both jars - this gave exactly the same result
Renaming all of the classes in the jar to eliminate duplicate class names like this: <attr path="/api/package[#name='com.hsm.barcode']/class[#name='DecodeOptions']" name="name">DecodeOptions2</attr>. When I do this, in reflector I can see that the class name has indeed changed, but I still get the build error when building the Xamarin.Android project
Renaming the namespace in one of the projects: <attr path="/api/package[#name='com.hsm.barcode']" name="name">com.hsm.barcode2</attr>. Again, I can see the updated namespace in reflector but still I get the same "Program type already present" error when building the Xamarin.Android project
Similarly I have tried removing both the namespace and the duplicate classes using remove-node but seen similar results
This leads me to believe that this isn't necessarily an issue with the binding process but rather a more Android related problem. I have found some similar Android questions where people mention that you can use exclude module in gradle to remove dependencies [1] [2], but a) there seems to be no concrete answer that this is the right approach in this case and b) as I have been able to find gradle is not a tool that is used as part of the Xamarin/Visual Studio process.
My final desperate attempt to get something working was to unzip one of the jar files, remove all the .class files that are causing issues, then rezip and use this in the Android binding library and then reference this dll in my Xamarin.Android project. This seems to work (the project builds and runs) but I'm not sure it is the correct/safest/most stable solution.
To summarize, the question is: if you have two jars with duplicated namespaces/packages and you want to use both of these Jars in a Xamarin.Android project how can you avoid the resulting Program type already present: com.hsm.barcode.DecodeOptions error message.

Xamarin Shared Library namespace cannot be found

My shared library cannot resolve using RestSharp; among other related namespaces. RestSharp is an installed package and is resolvable in the Droid/iOS projects but cannot be found in the Shared Library. I know this works because I'm using RestSharp in a MonoGame project in the same way. The shared library is referenced in the Droid/iOS projects but still fails during compilation.
Any advice? I tried clean all.
Update I created a new Cross Platform Native app solution and I was able to reference in my shared library without issue. That original project is a bit older and was created with PCL originally. I still want to know why it's not working in my original solution.
I continued to have lots of namespace and type not found issues. Once I showed warnings instead of just errors I found that the csproj was missing. After removing the reference in the native apps and re-adding the issue was resolved. Quite frusterating.

GENERATEFAKES fails with CS0234

My project builds for my teammates, but not for me.
Project:
Errors:
I deleted reference to mscorlib fake, recreated Fake for System, but got the same error.
If I try to add reference to mscorlib, I get message:
A reference to
'C:\Windows\Microsoft.NET\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
could not be added. This component is already automatically referenced
by the build system.
I tried to add <Reference Include="mscorlib" /> to the project file, but this did not resolve the issue.
I use VS 2017.
Will appreciate any clue.
Thank you #Abhitej, for the answer. It resolved the issue. In addition to switching to higher version of framework I added tags like <Remove FullName="System.Security.Cryptography.CryptoStream"/> for each failing class to both ShimGeneration and StubGeneration in .fakes file.
In most cases like this one its tied to the version of .Net Framework installed on the box. As long as your test project targets the highest version of the Framework on your box, this should work out. Also when dealing with System* namespace please be sure to only generate fakes for types you need excluding others. That should help Fakes deal with API changes over versions and resolve any build errors you might be seeing because of this.
-Abhitej.

Missing a using directive or an assembly reference error when I'm not missing anything

I have a solution with 4 projects. In the first one I reference the other three, not with Browse, but with Add reference->Project tab.
I have all three using statements in the beginning.
The program works fine. I tested it and it works. But I'm not able to build it.
I get the error "Missing a using directive or an assembly reference".
None of my projects are on client profile. (I think .Net 2.0 doesn't even have client profile).
Why is VS doing this? How to resolve it?
Clean build was the solution. Duh.

Resources