.Net Download link at run time

I have the following requirement:

  • I have a C # / application. Net that references the "System.Data.Sqlite.dll"
  • 'System.Data.Sqlite.dll' is not registered in the GAC (I do not want)
  • I do not want to store it in the directory where the executable (.exe) is stored.

  • How can I save the file "System.Data.Sqlite.dll" in some other directory and load it safely at runtime before it references the application code?

+3
source share
8 answers

For this you can use manual assembly permission.

AssemblyResolve AppDomain

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += assemblyResolver.ResolveEventHandler;

- , , , . , :

Assembly assembly = Assembly.LoadFrom (assemblyPath);
return assembly;

,

+9

, , , :

Assembly.LoadFrom Method (String path)

System.Reflection

& app.config

Assembly.LoadFrom MSDN

+4

. . . .

- exe, .

+4

Assembly.LoadFrom( )

, , , ?

+1

dll ( System.Reflection) Assembly.LoadFrom Type.GetType Type.GetMethod.

, dll, .

static string DynamicMethodCall(string dllPath, string someClass, string someMethodName, object[] parameters)
        {
            Assembly dll = Assembly.LoadFile(dllPath);

            Type type = dll.GetType(someClass);

            if (type == null)
            {
                Exception ex = new Exception("class not found");
                throw ex;
            }

            MethodInfo method = type.GetMethod(someMethodName);

            if (method == null)
            {
                Exception ex = new Exception("method not found");
                throw ex;
            }

            if (parameters.Length >= 1)
            {
                object[] myparam = new object[1];
                myparam[0] = parameters;
                return (string)method.Invoke(null, myparam);
            }
            else
            {
                return (string)method.Invoke(null, null);
            }
        }
+1

DLL EXE , , DLL EXE ( , , , DLL EXE). , , , SqlLite.

: DLL , DLL EXE .

0

I see no reason for links to assemblies other than an exe file, but one way to do this is to place them in a separate directory in the directory in which the exe file is located and include the app.config file in the sensing element.

0
source

You can use reflection: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.load%28VS.71%29.aspx

Be careful because of performance. Reflection should be used carefully.

0
source

Source: https://habr.com/ru/post/1712292/


All Articles