.net-assembly

Best way to check if a DLL file is a CLR assembly in C#

安稳与你 提交于 2019-12-17 22:15:17
问题 What is the best way to check if a DLL file is a Win32 DLL or if it is a CLR assembly. At the moment I use this code try { this.currentWorkingDirectory = Path.GetDirectoryName(assemblyPath); //Try to load the assembly. assembly = Assembly.LoadFile(assemblyPath); return assembly != null; } catch (FileLoadException ex) { exception = ex; } catch (BadImageFormatException ex) { exception = ex; } catch (ArgumentException ex) { exception = ex; } catch (Exception ex) { exception = ex; } if (exception

List of classes in an assembly

拈花ヽ惹草 提交于 2019-12-17 20:14:32
问题 I've a DLL assembly, in which there are various classes. Each class has around 50-100 members and 4-5 functions. How can I create a list of all the classes and their respective members using a VB.NET program? I need to show to the user for performing an operation using a particular class. 回答1: See the documentation for System.Reflection.Assembly.GetTypes() and System.Type.GetMembers() --larsw 回答2: Assuming that you've your assembly loaded to thisAsm (in this ex I'm using the executing

Preload all assemblies (JIT)

核能气质少年 提交于 2019-12-17 19:25:50
问题 We are taking a hit the first time some heavy UI screens are loaded. Our project is divided into one main executable and several DLL files. The DLL files can also contain UI screens which are slow the first time they are loaded. Is there a way (in code) we can preload all the referenced assemblies so as to avoid the JIT compilation hit? I know there is a tool called NGen. Is it possible to operate NGen in a development environment so we can see its effects instantly? Ideally though, we would

How to get the assembly (System.Reflection.Assembly) for a given type in .Net?

眉间皱痕 提交于 2019-12-17 18:48:52
问题 In .Net, given a type name, is there a method that tells me in which assembly (instance of System.Reflection.Assembly) that type is defined? I assume that my project already has a reference to that assembly, just need to know which one it is. 回答1: Assembly.GetAssembly assumes you have an instance of the type, and Type.GetType assumes you have the fully qualified type name which includes assembly name. If you only have the base type name, you need to do something more like this: public static

How to add PNG resource in Visual Studio 2010?

半城伤御伤魂 提交于 2019-12-17 18:48:25
问题 I have a PNG (i.e. a compressed image) that I'd like to include in my assembly (i.e. application). How to do it? Additional information: I tried adding a PNG resource to my assembly in Visual Studio 2010: But that didn't work, as Visual Studio converts it to an uncompressed bitmap: Except I want to add a PNG. Otherwise my 1MB application becomes 8MB: ]=== 1MB file size ==> ]=== 8MB file size ======================================================================================================

How can I get the executing assembly version?

本秂侑毒 提交于 2019-12-17 17:28:49
问题 I am trying to get the executing assembly version in C# 3.0 using the following code: var assemblyFullName = Assembly.GetExecutingAssembly().FullName; var version = assemblyFullName .Split(',')[1].Split('=')[1]; Is there another proper way of doing so? 回答1: Two options... regardless of application type you can always invoke: Assembly.GetExecutingAssembly().GetName().Version If a Windows Forms application, you can always access via application if looking specifically for product version.

Caching reflection data

纵饮孤独 提交于 2019-12-17 17:26:00
问题 What's the best way to cache expensive data obtained from reflection? For example most fast serializers cache such information so they don't need to reflect every time they encounter the same type again. They might even generate a dynamic method which they look up from the type. Before .net 4 Traditionally I've used a normal static dictionary for that. For example: private static ConcurrentDictionary<Type, Action<object>> cache; public static DoSomething(object o) { Action<object> action; if

Register CLR function (WCF based) in SQL Server 2012

≡放荡痞女 提交于 2019-12-17 16:57:36
问题 I have a CLR based stored procedure which used MsmqIntegrationBinding to post messages to remote MSMQ's. Everything was working fine in SQL Server 2005 but now there is an upgrade from 2005 to 2012 suppose to happen. I tried to register the CLR (SP) in SQL Server 2012 but while registering System.ServiceModell.DLL it came up with the following error. Msg 6544, Level 16, State 1, Line 1 CREATE ASSEMBLY for assembly 'System.ServiceModel' failed because assembly 'microsoft.visualbasic.activities

Why a machine with .NET 4 installed on it cannot run an exe that targeted .NET 4.5 while if they use the same CLR version?

社会主义新天地 提交于 2019-12-17 16:11:55
问题 In Common Language Runtime (CLR) Microsoft page, it says that both .Net Framework 4 and 4.5 uses the CLR version 4. However in this page (.NET Framework Versions and Dependencies) it writes '.Net Framework version 4.5 Included an updated version of CLR 4' Also writes: ' An executable that targets the .NET Framework 4.5.1 will be blocked from running on a computer that only has the .NET Framework 4.5 installed, and the user will be prompted to install the .NET Framework 4.5.1. In addition,

Working with AppDomain.AssemblyResolve event

[亡魂溺海] 提交于 2019-12-17 06:51:50
问题 I'm trying to use AppDomain.AssemblyResolve event to handle exceptions while resolving Assemblies of some dll loaded at runtime (SerializationException for dynamically loaded Type). When the event is fired, I load all DLLs in my directory and create an Assembly array, then I use this method to get the Assembly containing the type I specify: public static Assembly GetAssemblyContainingType(String completeTypeName, Assembly[] assemblies) { Assembly assembly = null; foreach (Assembly