assemblies

Prevent external assembly injection via PublicKeyToken

本秂侑毒 提交于 2019-11-29 18:05:27
问题 I'm using the following code: AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => { var token = args.LoadedAssembly.GetName().GetPublicKeyToken(); if (!IsValidToken(token)) { Process.GetCurrentProcess().Kill(); } }; Where IsValidToken() compares the public key token of the assembly being loaded against a list of authorized public key tokens hardcoded in my application as byte arrays. Is this a good security measure to prevent code injection attacks? Also, is this necessary given the

C# type defined in an assembly that is not referenced

隐身守侯 提交于 2019-11-29 17:20:24
问题 I have two projects A and B. Project A makes use of type X in project B, so I have a reference to B added in A. Everything built fine. I signed project B using a strong named key file. Everything still built fine. Then I decided to change the strong named key file for B. I rebuilt project B ok. When I try to build project A I receive the error "Error 1 The type X is defined in an assembly that is not referenced. You must add a reference to assembly B, Version=1.0.0.0, Culture=neutral,

Read embedded file from assembly

我们两清 提交于 2019-11-29 17:15:43
I have to pass the path of a config file to a framework method (Gurok SmartInspect). The config file is an embedded resource of the assembly. Currently I read the file from the assembly and store it outside and then pass the pathName. Is there a better / less complicated way to achieve this goal, without copying the file? private static void ConfigLogger() { const string embeddedFileName = "xxx.SmartInspect.properties"; const string configFileName = "SmartInspect.properties"; ExtractFileFromAssembly(embeddedFileName, configFileName); SiAuto.Si.LoadConfiguration(configFileName); } private

Loading Assemblies from a .Net Application in a 'Sandbox Environment'

半世苍凉 提交于 2019-11-29 15:47:37
问题 I am currently developing an application in where a user will dynamically choose dlls and the application will execute some of the methods in that dll. ( if you follow the first link, you will see that I am developing a sort of Robocode game application using the .Net Framework ). For example, when the battle starts, the run method from the dll is executed. Since whatever was specified in the run method will be executed, there are quite a bit of Security Constraints that have to be applied.

Assembly Loading Version Mismatch: Why is it loading?

妖精的绣舞 提交于 2019-11-29 15:27:51
问题 I have two assemblies: HelloWorld.exe and Hello.dll. The exe is the main assembly and the dll is being used by the main assembly. I compiled both HelloWorld.exe (1.0.0) and Hello.dll (1.0.0). I placed the assemblies on a different folder. I then changed the version of Hello.dll to 2.0.0 and proceeded to overwrite the Hello.dll 1.0.0 with the 2.0.0 version. I then launch HelloWorld.exe and it worked fine. I expected it to crash and burn immediately because the referenced Hello.dll when I

Mono.Cecil: call GENERIC base class' method from other assembly

最后都变了- 提交于 2019-11-29 14:46:57
问题 I'm following up on my earlier question: Mono.Cecil: call base class' method from other assembly. I'm doing the same thing, but if my base class is generic it doesn't work. //in Assembly A class BaseVM<T> {} //in Assembly B class MyVM : Base<SomeModel> { [NotifyProperty] public string Something {get;set;} } It weaves the following code: L_000e: call instance void [AssemblyA]Base`1::RaisePropertyChanged(string) instead of L_000e: call instance void [AssemblyA]Base`1<class SomeModel>:

Mixed mode assembly is built against version '2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime

强颜欢笑 提交于 2019-11-29 14:41:15
问题 I'm using Visual Studio 2012 and the .Net Framework 4.5 I have 2 Solutions: 1) WPF Application 2) Class library (dll) The Class Library contains 3 buttons and a control that has to be inside a WindosFormsHost control since it was made for WinForms. The only referenced assemblies outside of the .NET Framework ones are for the aforementioned winforms control and iTextSharp. The winforms control seems to be kinda old and when I put the reference in my dll I got the same error as the title but

Loading an assembly generated by the Roslyn compiler

别来无恙 提交于 2019-11-29 14:36:38
问题 I'm generating a Greeter.dll using the Roslyn compiler. My problem occurs trying to load the DLL file. Here's the code: using System; using Roslyn.Compilers; using Roslyn.Compilers.CSharp; using System.IO; using System.Reflection; using System.Linq; namespace LoadingAClass { class Program { static void Main(string[] args) { var syntaxTree = SyntaxTree.ParseCompilationUnit(@" class Greeter { static void Greet() { Console.WriteLine(""Hello, World""); } }"); var compilation = Compilation.Create(

Is it possible to reference different version of the same assembly into a single project?

家住魔仙堡 提交于 2019-11-29 14:08:34
In my solution, I have several projects which use Log4Net (1.2 and 2.5). Then I have a project where I do all the unit testing (of the other projects). So I'm in a situation where depending on what I test/mock I would need Log4Net 1.2 or 2.5. I read you could support different version of a single assembly in an application (using codebase etc.) but is it even possible to support different version of a single assembly into a project? If so, how? EDIt: Here's a tiny (2 classes, 2 methods, 2 constructors) project showing my issue: https://srv-file1.gofile.io/download/EQFdOs/212.76.254.142

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

隐身守侯 提交于 2019-11-29 13:24:03
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 a couple assemblies that I need it to have. The assemblies I need are managed (c# .net 4), are