assemblies

Dynamically replace the contents of a C# method?

血红的双手。 提交于 2019-11-26 02:49:14
What I want to do is change how a C# method executes when it is called, so that I can write something like this: [Distributed] public DTask<bool> Solve(int n, DEvent<bool> callback) { for (int m = 2; m < n - 1; m += 1) if (m % n == 0) return false; return true; } At run-time, I need to be able to analyse methods that have the Distributed attribute (which I already can do) and then insert code before the body of the function executes and after the function returns. More importantly, I need to be able to do it without modifying code where Solve is called or at the start of the function (at

Difference between LoadFile and LoadFrom with .NET Assemblies?

北城余情 提交于 2019-11-26 02:07:56
问题 I was looking at the msdn documentation and I am still a little confused on what exactly is the difference between using LoadFile and LoadFrom when loading an assembly. Can someone provide an example or an analogy to better describe it. The MSDN documentation confused me more. Also, Is ReflectionOnlyLoadFrom the same as LoadFrom except that it loads the assembly only in reflection mode. Since my .NET experience is not the greatest, here are some questions regarding the MSDN documentation

Why should you remove unnecessary C# using directives?

99封情书 提交于 2019-11-26 01:53:30
问题 For example, I rarely need: using System.Text; but it\'s always there by default. I assume the application will use more memory if your code contains unnecessary using directives. But is there anything else I should be aware of? Also, does it make any difference whatsoever if the same using directive is used in only one file vs. most/all files? Edit: Note that this question is not about the unrelated concept called a using statement, designed to help one manage resources by ensuring that when

Dynamically replace the contents of a C# method?

拜拜、爱过 提交于 2019-11-26 01:41:15
问题 What I want to do is change how a C# method executes when it is called, so that I can write something like this: [Distributed] public DTask<bool> Solve(int n, DEvent<bool> callback) { for (int m = 2; m < n - 1; m += 1) if (m % n == 0) return false; return true; } At run-time, I need to be able to analyse methods that have the Distributed attribute (which I already can do) and then insert code before the body of the function executes and after the function returns. More importantly, I need to

How to Load an Assembly to AppDomain with all references recursively?

爷,独闯天下 提交于 2019-11-26 00:36:10
问题 I want to load to a new AppDomain some assembly which has a complex references tree (MyDll.dll -> Microsoft.Office.Interop.Excel.dll -> Microsoft.Vbe.Interop.dll -> Office.dll -> stdole.dll) As far as I understood, when an assembly is being loaded to AppDomain , its references would not be loaded automatically, and I have to load them manually. So when I do: string dir = @\"SomePath\"; // different from AppDomain.CurrentDomain.BaseDirectory string path = System.IO.Path.Combine(dir, \"MyDll

How to merge multiple assemblies into one?

人盡茶涼 提交于 2019-11-26 00:32:45
问题 I consuming my service stack using EXE project (startup task for azure application) in that I have copied following service stack\'s DLL & some Azure\'s DLLs in to EXE project. When I build this EXE project then Azure DLLs will be bundled with my EXE but service stack\'s DLL will not be bundled with EXE, because to run my EXE on any machine I need to copy all service stack\'s DLL manually. I have used this service stack\'s dll to use JsonServiceClient client = new JsonServiceClient

Can I load a .NET assembly at runtime and instantiate a type knowing only the name?

久未见 提交于 2019-11-25 23:49:07
问题 Is it possible to instantiate an object at runtime if I only have the DLL name and the class name, without adding a reference to the assembly in the project? The class implements a interface, so once I instantiate the class, I will then cast it to the interface. Assembly name: library.dll Type name: Company.Project.Classname EDIT: I dont have the absolute path of the DLL, so Assembly.LoadFile won\'t work. The DLL might be in the application root, system32, or even loaded in the GAC. 回答1: Yes.

How to determine if a .NET assembly was built for x86 or x64?

二次信任 提交于 2019-11-25 23:20:32
问题 I\'ve got an arbitrary list of .NET assemblies. I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible? 回答1: Look at System.Reflection.AssemblyName.GetAssemblyName(string assemblyFile) You can examine assembly metadata from the returned AssemblyName instance: Using PowerShell : [36] C:\> [reflection.assemblyname]::GetAssemblyName("${pwd}\Microsoft.GLEE.dll") | fl Name : Microsoft.GLEE Version : 1.0.0.0 CultureInfo : CodeBase : file:///C

How to enable assembly bind failure logging (Fusion) in .NET

青春壹個敷衍的年華 提交于 2019-11-25 22:54:55
问题 How do I enable assembly bind failure logging (Fusion) in .NET? 回答1: Add the following values to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion Add: DWORD ForceLog set value to 1 DWORD LogFailures set value to 1 DWORD LogResourceBinds set value to 1 DWORD EnableLog set value to 1 String LogPath set value to folder for logs (e.g. C:\FusionLog\) Make sure you include the backslash after the folder name and that the Folder exists . You need to restart the program that you're running to force it to

How to add folder to assembly search path at runtime in .NET?

[亡魂溺海] 提交于 2019-11-25 22:49:58
问题 My DLLs are loaded by a third-party application, which we can not customize. My assemblies have to be located in their own folder. I can not put them into GAC (my application has a requirement to be deployed using XCOPY). When the root DLL tries to load resource or type from another DLL (in the same folder), the loading fails (FileNotFound). Is it possible to add the folder where my DLLs are located to the assembly search path programmatically (from the root DLL)? I am not allowed to change