assemblies

Detect whether the assembly was built for .NET Compact Framework

强颜欢笑 提交于 2019-12-01 07:05:03
问题 Having a .NET assembly, how can I detect whether it was built for .NET CF or a full framework? 回答1: It's quite simple: public enum AssemblyType { CompactFramework, FullFramework, NativeBinary } public AssemblyType GetAssemblyType(string pathToAssembly) { try { Assembly asm = Assembly.LoadFrom(pathToAssembly); var mscorlib = asm.GetReferencedAssemblies().FirstOrDefault(a => string.Compare(a.Name, "mscorlib", true) == 0); ulong token = BitConverter.ToUInt64(mscorlib.GetPublicKeyToken(), 0);

When does the CLR try to load a referenced assembly?

☆樱花仙子☆ 提交于 2019-12-01 06:53:01
I want to write a small installer app that installs a web site and creates IIS virtual directories. The app should run on Windows XP/Server 2003 (IIS 6) as well as on Vista/2008 (IIS 7). The problem is: for IIS 6 we create virt dirs by calling WMI/Metabase API, for IIS 7 there is a much better API: Microsoft.Web.Administration, but its assembly is available only on IIS 7 systems. Naive approach: ... if (OperatingSystem == old) { call metabase API... } else { call Microsoft.Web.Administration... } ... Nice, isn't it? But how can I make sure that this does not crash on a old system just while

How can I switch .NET assembly for execution of one method?

青春壹個敷衍的年華 提交于 2019-12-01 06:47:15
I have different versions of dlls for my .NET application and most of the time I want to use the latest one. However, there is one method which I run on a separate thread where I need to be able to select an older version of the dll based on some criteria. I have learned that it is not possible to just load an assembly and then unload it within the default application domain (I can't just keep both versions loaded because then I'm running into duplicate definitions of types problem) Probably I have to create a separate AppDomain, load the assembly there and then unload it. This application

How to compile CIL code?

我怕爱的太早我们不能终老 提交于 2019-12-01 06:26:50
问题 I have a code written in CIL . Let's say, a file called some_il_code.il holds it. I want to compile it to create a managed exe assembly. How do I achieve that? 回答1: You can use the ilasm tool. ilasm /exe Your.il /deb=opt peverify /md /il Your.exe ilasm compiles it, peverify verifies it. 来源: https://stackoverflow.com/questions/12741607/how-to-compile-cil-code

ASP.NET hostingEnvironment / shadowCopyBinAssemblies

旧时模样 提交于 2019-12-01 05:10:02
Today I stumpled upon the shadowCopyBinAssemblies option in the hostingEnvironment tag. Appearently this attribute it is a web.config (system.web) configuration Boolean option indicating whether the assemblies of an application in the Bin directory are shadow copied to the application's ASP.NET Temporary Files directory. <hostingEnvironment shadowCopyBinAssemblies="false" /> A colleague had to enable this setting because (only) on his development machine he frequently got that ASP.NET error in the web browser: Cannot create shadow copy assembly file dll when that file already exists. compiling

How to identify that an assembly has been compiled with/for .NET 4.5, as opposed to .NET 4.0?

▼魔方 西西 提交于 2019-12-01 04:39:46
I have some build agents that is building .NET code for us through a TeamCity setup, and I'm beginning to wonder if despite the project settings, they're outputting .NET 4.5 built assemblies. My doubts come from the fact that I don't know if Windows 2012 Server came with .NET 4.5 or 4.0 out of the box and thus whether it ever has had only 4.0 or any of the 4.0 assemblies available. How can I look at a assembly on disk and determine whether it has been built with .NET 4.0 or 4.5? As is evident by this blog post by Marc Gravell , there are differences in how these assemblies are built, even

How can I switch .NET assembly for execution of one method?

假如想象 提交于 2019-12-01 04:38:30
问题 I have different versions of dlls for my .NET application and most of the time I want to use the latest one. However, there is one method which I run on a separate thread where I need to be able to select an older version of the dll based on some criteria. I have learned that it is not possible to just load an assembly and then unload it within the default application domain (I can't just keep both versions loaded because then I'm running into duplicate definitions of types problem) Probably

Visual Basic, why can't I import “System.Drawing” when my only reference is “System”?

对着背影说爱祢 提交于 2019-12-01 04:08:45
In Visual Studio 10 - Visual Basic, why can't I import "System.Drawing" when my only reference is "System"? I can import "System.Runtime.InteropServices". To reproduce my problem: 1. Create a New Project in Visual Studio 10 with Visual Basic Class Library template. 2. Add "Imports System.Drawing" and "Imports System.Runtime.InteropServices" at the beginning. 3. Remove all references except "System" in the References pane of the project properties. Result: Visual Studio cannot find "System.Drawing" but it can find "System.Runtime.InteropServices". "System.Drawing" is fully qualified so the

Visual Studio adding executable file with same name as dll

我的梦境 提交于 2019-12-01 04:07:36
In Visual Studio 2008, I added WinScp.dll (in project root) as a reference and immediately there was a yellow icon. At compile-time: The type or namespace name 'WinSCP' could not be found (are you missing a using directive or an assembly reference?) Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'E:...\winscp.exe' or one of its dependencies. The module was expected to contain an assembly manifest. After an hour's frustration, I figured out that if I removed WinSCP.exe as a project file (also in project root), everything compiled fine.

C# add a reference using only code (no IDE “Add Reference” functions)

北战南征 提交于 2019-12-01 03:42:49
问题 I am writting a plugin for a program, and I want to put my code inside a DLL so I can share the plugin freely without exposing (giving away) my code. Here is the basic structure i have access to : using System; public class Plugin { public void Initialize() { //do stuff here doWork(); } } Then i just reference the .cs file my code is at and the program "eats" up this Plugin. Now, i have put several logic in there, consisting mostly of functions that arent tied directly to "Initialize()", only