Combine WPF application with C # and VB.NET code

I have an application written in C# that needs some functionality from VB.NET (better said, something is really in CIL , but not specified in C# ).
Therefore, I have an executable and a library file.

Problem:
It must be published in one file and cannot be divided into different assemblies!
But:
This is a WPF application, ILMerge will not work.

What can I do?
Is it possible to generate IL (IL) on the fly?

+6
source share
3 answers

See this question (and various answers) for combining WPF exe and dll library together:
Combining dll into one .exe with wpf

See this answer for the C # exception filter version (may not be applicable in your case, here for future reference):
More elegant exception handling than multiple catch blocks?

+2
source

I suggest you create two assemblies during assembly, and then insert one into the other as a resource. That way you can call Assembly.Load () and load this secondary assembly.

 using (var stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } 

See http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx for details.

+1
source

You can have one assembly, but with several modules compiled in different languages. You would create three projects:

  • VB.NET specific code project
  • C # code project
  • Exe project

Now you cannot use Visual Studio to create it (AFAIK, but you can play with project / MSBUILD files for this), but you must use command line compilers to create network modules.

Using csc.exe (for C #), you should use the /target:module command-line option, and with vbc.exe (for VB.NET), you should also use the /target:module command-line option.

Then, when creating the EXE project, you should use the command line compiler (depending on the language) and use /addmodule:<module> (assuming the EXE project is in C #) or /addmodule:<module> (assuming the EXE project located in VB.NET) to point to the modules that you specified for inclusion in the EXE assembly.

You also have the option of compiling everything into modules and using Assembly Linker (Al.exe) to create an output assembly .

If the above option does not suit you, then another option is to choose one language and use it.

If you use VB.NET, then you will have exception filters (which you specified is the fragment that you need, which is a language function, and not open through the framework).

If you use C #, you do not have exception filters, but you can simulate them as indicated by George Duckett to respond .

+1
source

Source: https://habr.com/ru/post/900204/


All Articles