assemblies

How to use Assembly Binding Redirection to ignore revision and build numbers

落花浮王杯 提交于 2019-11-26 12:27:48
问题 I have several .NET applications in C#, along with an API for them to access the database. I want to put all versions of the API in the database, and have them pick the highest revision and build number, but stick with the major and minor number they were built with. Basically when I reference API 1.2.3.4 I want the reference to read 1.2.*.* so that the applications just pick up 1.2.3.5 I see I can do this with XML config files. I\'d rather have it complied in. Similar to publish policies,

How to reference .NET assemblies using PowerShell

不问归期 提交于 2019-11-26 12:25:36
问题 I am a C# .NET developer/architect and understand that it uses objects (.NET objects) and not just streams/text. I would like to be able to use PowerShell to call methods on my .NET (C# library) assembies. How do I reference an assembly in PowerShell and use the assembly? 回答1: Take a look at the blog post Load a Custom DLL from PowerShell : Take, for example, a simple math library. It has a static Sum method, and an instance Product method: namespace MyMathLib { public class Methods { public

Can strong naming an assembly be used to verify the assembly author?

隐身守侯 提交于 2019-11-26 12:09:43
问题 I have been reading the proper article in MSDN, Strong-Named Assemblies and a related Stack Overflow question, Checking an assembly for a strong name . To which extent can a strong-named assembly be verified to avoid tampering? Is it possible to use strong-naming to verify an assembly author? The first question arises after reading the CSharp411 article .NET Assembly FAQ – Part 3 – Strong Names and Signing , which mentions this, among other problems of using strong names: \" Cannot Stop Full

Initialize library on Assembly load

寵の児 提交于 2019-11-26 11:28:41
问题 I have a .net library dll that acts like a functional library. There are a bunch of static types along with static methods. There is some initialization code that I need to run to set up the library ready for use. When the assembly gets loaded is there a way to ensure that a particular method is run? Something like AppDomain.AssemblyLoad but called automatically from the assembly itself. I was thinking that maybe there is something like an AssemblyAttribute that could be used? At the moment I

Finding all Namespaces in an assembly using Reflection (DotNET)

若如初见. 提交于 2019-11-26 11:21:22
问题 I\'ve got an assembly (loaded as ReflectionOnly) and I want to find all the namespaces in this assembly so I can convert them into \"using\" (\"Imports\" in VB) statements for an auto-generated source code file template. Ideally I\'d like to restrict myself to top-level namespaces only, so instead of: using System; using System.Collections; using System.Collections.Generic; you\'d only get: using System; I noticed there is a Namespace property on the System.Type class, but is there a better

Difference between LoadFile and LoadFrom with .NET Assemblies?

旧城冷巷雨未停 提交于 2019-11-26 11:15:37
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 using LoadFile: 1) What does it mean by LoadFile examines assemblies that have the same Identity, but are

Custom Assembly Attributes

↘锁芯ラ 提交于 2019-11-26 10:31:04
问题 I would like to know if I can define custom assembly attributes. Existing attributes are defined in the following way: [assembly: AssemblyTitle(\"MyApplication\")] [assembly: AssemblyDescription(\"This application is a sample application.\")] [assembly: AssemblyCopyright(\"Copyright © MyCompany 2009\")] Is there a way I can do the following: [assembly: MyCustomAssemblyAttribute(\"Hello World! This is a custom attribute.\")] 回答1: Yes you can. We do this kind of thing. [AttributeUsage

How to extract an assembly from the GAC?

只愿长相守 提交于 2019-11-26 10:07:09
问题 There is a package I have to deal with which installs assemblies straight into the GAC (e.g. somewhere deep in %windows%/assembly). How do I exorcise the actual assembly (the DLL) from the GAC into the normal file system? Thanks. 回答1: I used the advice from this article to get an assembly from the GAC. Get DLL Out of The GAC DLLs once deployed in GAC (normally located at c:\windows\assembly) can’t be viewed or used as a normal DLL file. They can’t be directly referenced from VS project.

How do I find the fully qualified name of an assembly?

时光毁灭记忆、已成空白 提交于 2019-11-26 09:28:15
问题 How do I find out the fully qualified name of my assembly such as: MyNamespace.MyAssembly, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 I\'ve managed to get my PublicKeyToken using the sn.exe in the SDK, but I\'ld like to easily get the full qualified name. 回答1: If you can load the assembly into a .NET application, you can do: typeof(SomeTypeInTheAssembly).Assembly.FullName If you cannot then you can use ildasm.exe and it will be in there somewhere: ildasm.exe

how to load all assemblies from within your /bin directory

点点圈 提交于 2019-11-26 09:23:24
问题 In a web application, I want to load all assemblies in the /bin directory. Since this can be installed anywhere in the file system, I can\'t gaurantee a specific path where it is stored. I want a List<> of Assembly assembly objects. 回答1: Well, you can hack this together yourself with the following methods, initially use something like: string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); to get the path to your current assembly. Next, iterate over all DLL's in the