Understanding .NET Assembly Reference Differences - c#

I have two nearly identical DLLS (for the same open source project) - one was pre-compiled, and one was compiled locally by my own compiler (Xamarin Studio/Mono).
The DLL I compiled isn't working with the application that's supposed to be using it (while the pre-built one does), so I grabbed a decompiler to see if I can track down any differences (file sizes were slightly different):
I suspect the reference differences might be the problem. The TOP one is the manually compiled dll. How can I resolve this and make the references identical to the bottom dll's? I've tried using the Mono/.NET 3.5 option in the settings, but it resulted in errors complaining about default parameter specifiers in a bunch of places, so it seems as if it's meant to be compiled w/4.0. Here's a cap of the build settings options (only the Mono/.NET 4.0 option works):
What's causing the differences in assembly references?

Microsoft introduces the multi-targeting feature in its C# compiler, so that C# 4/5 compiler (csc.exe) can generate .NET 2.0/3.0/3.5 compatible assemblies. That's how the pre-compiled assembly comes from.
Unfortunately it is a long time issue for MonoDevelop, that it does not support such multi-targeting. For example, you cannot choose Mono/.NET 3.5 and expect Xamarin Studio/MonoDevelop to use the latest mcs compiler. It always uses the one for .NET 3.5 profile, and fails to compile if you use any C# 4/5 syntax.
You might try to use xbuild at terminal to compile, as xbuild does support multi-targeting. However, you might come across xbuild issues, as it is not yet as capable as MSBuild.

Related

Which versions of which compilers I should use to have C# 9 compiler?

Here it was written that compilers of different versions are applied sequentially to build the latest version of compiler.
I don't want to use binaries provided by Microsoft. I want to have everything be compiled from source codes.
Which repositories I should compile exactly? Do they all have open source licenses?
The runtime and the compiler for .NET 5.0 are open-source. You can start by going to https://github.com/dotnet/runtime. However, building the runtime requires the compiler (which will be downloaded by running the build script). So there's little you can do to avoid getting binaries that were built by Microsoft. If you're afraid that they're fake (and in some way different from what you would get if you directly built everything from source) you'll probably have to go a different way.

VS2013 C# projects in VS2015: Will they use the Roslyn compiler?

Not entirely certain that this is even a valid question, however if I use VS2015 to open a solution that was originally created and maintained with VS2013, will it be compiled using the Roslyn compiler platform whenever built (within VS2015)?
The solution consists of WPF applications, Console applications, Web Applications, Windows Service applications and of course class libraries - so a good all round selection of options.
If this is not the case, how should I enable the Roslyn compiler for these projects?
Thanks.
If you open in VS2015, it will always use the Roslyn compiler to compile, regardless of the language version switch.
Using the /langversion switch simply tells the Roslyn compiler not to allow new features - it doesn't cause an older compiler to be used.

Targeting UWP with csc.exe

I'm trying to get IKVM working for Windows 10 UWP targets. I'm running into problems with the code I'm compiling with csc.exe. If I target .Net 4.0 or higher, then I get runtime errors like:
Method not found: 'Boolean System.Reflection.Assembly.op_Equality(System.Reflection.Assembly, System.Reflection.Assembly)'.
Because the '==' operator overload was supported in 4.0 or higher, but apparently some of the assemblies in UWP don't support this.
If I, instead, target .Net < 4.0 (e.g. 2.0 or 3.5), I get errors like:
Attempt by method 'IKVM.Internal.AssemblyClassLoader+AssemblyLoader..ctor(System.Reflection.Assembly)' to access method 'System.Reflection.Assembly.GetModules(Boolean)'
I think that this is to do with .net security not allowing me to access reflection from "secure" assemblies from my "insecure" assemblies.... and my assemblies are deemed "insecure" because they are compiled for 2.0/3.5 which predates the security model in play here.
Question:
How do I compile my C# files to target exactly the version of .Net that is used in UWP apps? (The build is taking place through a Nant build file via the <csc> tag).
Thanks for any pointers.
UPDATE:
I have found one way to target UWP's .Net libraries, and that is to make Visual Studio projects for each of the IKVM runtime projects - and build using that instead of Nant. I would still like to find a way to use the existing Nant build files, but so far it doesn't look like Nant supports building for UWP.

Assemblies Visual Studio 2010 using in monodevelop with monotouch

I'm new in monodevelop and I have a question.
I have some assemblies developed in Visual Studio 2010 in C# and I would like to use them with monotouch in Mac, my question is: do I have to use the source and generate the assemblies with monodevelop in Mac or just I need the assemblies and add them to my solution as a reference?
The framework profile used by MonoTouch was originally based on the Silverlight profile (aka 2.1) and was updated to include some, but not all, of the new API provided by the .NET framework 4.0.
As such you might be able to reuse assemblies, without recompiling them. That will depends if all the API are available, if you refer to assemblies not available in MonoTouch, under what profile (3.5 or 4.0) you're building the code...
However things would be a lot easier if you have the source code and are able to re-compile it inside MonoDevelop. That would provide you with debugging symbols (the .mdb files) also also catch, at compile time (not at run time), and fix code using any missing API (from MonoTouch).
You should be able to use the same assemblies as they are (no need for a recompile). If the assemblies depend on other nonstandard assemblies it might get tricky and you may have to deploy other assemblies along side the ones you want and then that may cause it's own problems if they are not open source or licenses are required to redistribute, etc.. Give it a shot, see what happens.

How do I add a .NET Runtime in Edit->Prefrences?

Ok I am using Windows and have .Net 3.5 and the Mono 2.6 frameworks installed. I also have installed MonoDevelop and plan on using it. I just need to know if I am setup to use the Mono runtime.
All my projects have build options for Mono/Microsoft.NET 3.5, but in Edit->Prefrences->.NET Runtimes, all I see is Microsoft.NET. How do I add the Mono runtime to this list and make it default? Or do I even need to do this? I would think I would have to since our projects will be run on Linux, but not sure how to 'make sure' I am actually using Mono and not just .NET?
Mono should show up simply by virtue of being installed. You can try reinstalling Mono to see if that helps.
If not, click the "Add" button on the Edit->Preferences->.Net Runtimes page and choose where you installed Mono to, generally it will be something like:
C:\Program Files\Mono-2.6.1
If you want it to be the default, click "Set as Default" while it's highlighted and it should turn bold, indicating it is now the default. There is also a combobox on the main MD toolbar if you want a quicker way of switching between runtimes.
You shouldnt HAVE to build using Mono's compiler on Windows to have your code run on Linux.
As per answers on Performance: Compile in CS, Run in mono on windows and linux, you can compile with any compiler and run with any runtime because the compiled binary is in an Intermediate Language
You just have to be certain that your code, and the libraries that it uses, do not make operating system specific calls, P/Invoke unmanaged DLL's, or make calls to functions that are incomplete in Mono (mind you, these are getting rare)

Categories