assemblies

Not all assemblies are being loaded into AppDomain from the bin folder

夙愿已清 提交于 2019-11-28 06:58:42
问题 I have the following method that should retrieve a list of loaded local (in bin folder) assemblies: static IEnumerable<Assembly> GetLocalAssemblies() { Assembly callingAssembly = Assembly.GetCallingAssembly(); string path = new Uri(Path.GetDirectoryName(callingAssembly.CodeBase)).AbsolutePath; var assemblies = AppDomain.CurrentDomain.GetAssemblies(); return assemblies.Where(x => !x.IsDynamic && new Uri(x.CodeBase).AbsolutePath.Contains(path)).ToList(); } But, the list of assemblies is missing

Secure C# Assemblies from unauthorized Callers

谁都会走 提交于 2019-11-28 06:54:21
Is there any way to secure your assembly down to the class/property & class/method level to prevent the using/calling of them from another assembly that isn't signed by our company? I would like to do this without any requirements on strong naming (like using StrongNameIdentityPermission) and stick with how an assembly is signed. I really do not want to resort to using the InternalsVisibleTo attribute as that is not maintainable in a ever changing software ecosystem. For example: Scenario One Foo.dll is signed by my company and Bar.dll is not signed at all. Foo has Class A Bar has Class B

Referencing different versions of the same assembly

六月ゝ 毕业季﹏ 提交于 2019-11-28 06:45:45
If A references assembly B 1.1 and C, and C references B 1.2, how do you avoid assembly conflicts? I nievely assumed C's references would be encapsulated away and would not cause any problems, but it appears all the dll's are copied to the bin, which is where the problem occurs. I understand the two ways around this are to use the GAC or assembly bindings? The GAC doesn't seem like the best approach to me, as I don't like assuming dlls will be there, I prefer to reference dlls from a lib directory in my solution. Where as assembly bindings don't seem robust to me, what if one version of the

How to determine whether a DLL is a managed assembly or native (prevent loading a native dll)?

情到浓时终转凉″ 提交于 2019-11-28 06:22:36
Original title: How can I prevent loading a native dll from a .NET app? Background: My C# application includes a plugin framework and generic plugin loader. The plugin loader enumerates the application directory in order to identify plugin dlls (essentially it searches for *.dll at this time). Within the same application directory is a native (Windows, non-.net) dll, which, indirectly, one of the plugin dlls depends upon. The plugin loader blindly assumes that the native.dll is a .NET Assembly dll, simply because it only checks the file extension. When it attempts to load the native dll, an

How to prevent others from using my .Net assembly?

狂风中的少年 提交于 2019-11-28 06:04:20
I have an assembly which should not be used by any application other than the designated executable. Please give me some instructions to do so. You can sign the assembly and the executable with the same key and then put a check in the constructor of the classes you want to protect: public class NotForAnyoneElse { public NotForAnyoneElse() { if (typeof(NotForAnyoneElse).Assembly.GetName().GetPublicKeyToken() != Assembly.GetEntryAssembly().GetName().GetPublicKeyToken()) { throw new SomeException(...); } } } In .Net 2.0 or better, make everything internal, and then use Friend Assemblies http:/

How do I create and use a .NET metadata-only 'Reference Assembly'?

天涯浪子 提交于 2019-11-28 05:52:48
Since version 3.0, .NET installs a bunch of different 'reference assemblies' under C:\Program Files\Reference Assemblies\Microsoft...., to support different profiles (say .NET 3.5 client profile, Silverlight profile). Each of these is a proper .NET assembly that contains only metadata - no IL code - and each assembly is marked with the ReferenceAssemblyAttribute . The metadata is restricted to those types and member available under the applicable profile - that's how intellisense shows a restricted set of types and members. The reference assemblies are not used at runtime. I learnt a bit about

Modifying Existing .NET Assemblies

若如初见. 提交于 2019-11-28 05:30:35
Is there a way to modify existing .NET assemblies without resorting to 3rd party tools? I know that PostSharp makes this possible but I find it incredibly wasteful that the developler of PostSharp basically had to rewrite the functionality of the whole System.Reflection namespace in order to make existing assemblies modifiable. System.Reflection.Emit only allows the creation of new, dynamic assemblies. However, all the builder classes used here inherit from the basic reflection classes (e.g. TypeBuilder inherits from System.Type ). Unfortunately, there doesn't seem to be a way to coerce an

Two different assembly versions “The located assembly's manifest definition does not match the assembly reference”

落爺英雄遲暮 提交于 2019-11-28 05:07:52
问题 I have a project that I am working on that requires the use of the Mysql Connector for NHibernate, (Mysql.Data.dll). I also want to reference another project (Migrator.NET) in the same project. The problem is even though Migrator.NET is built with the reference to MySql.Data with specific version = false, it still tries to reference the older version of MySql.Data that the library was built with instead of just using the version that is there.. and I get the exception listed in the title: ---

Mixed mode assembly is built against version X and cannot be loaded in version Y of the runtime without additional configuration information

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 04:09:15
问题 After doing some code refactoring, my VS2010 VB.Net Web Application project has stopped compiling with the following error: "Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information." In the 'File' column of the Visual Studio's error list is the word 'SGEN', but when I double-click, the file does not exist ("The document cannot be opened. It has been renamed, deleted or moved.") I gather it has

Using the Web Application version number from an assembly (ASP.NET/C#)

蹲街弑〆低调 提交于 2019-11-28 04:04:30
How do I obtain the version number of the calling web application in a referenced assembly? I've tried using System.Reflection.Assembly.GetCallingAssembly().GetName() but it just gives me the dynamically compiled assembly (returning a version number of 0.0.0.0). UPDATE: In my case I needed a solution that did not require a reference back to a class within the web application assembly. Jason's answer below (marked as accepted) fulfils this requirement - a lot of others submitted here don't. Here is some code I use that supports getting the application's "main" assembly from either Web or non