Autor Beitrag
Mips
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Sa 25.10.08 15:59 
Hallo zusammen,

ich versuche im Moment eine dll auf ihre enthaltenen Klasse zu untersuchen. Dies sollte mit
System.Reflection.Assembly kein Problem sein. Also habe ich dieses kleine Programm geschrieben.

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Text;

namespace Assemblys
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                System.Reflection.Assembly plugin = System.Reflection.Assembly.Load("plugin.dll");
                Type[] pclass = plugin.GetTypes();

                foreach (Type p in pclass)
                {
                    if (p.IsClass)
                        Console.WriteLine(p.FullName + " is a plugin class in plugin.dll");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                System.Threading.Thread.Sleep(10);
            }
            finally {
                System.Threading.Thread.Sleep(10);
            }
        }
    }


Und noch eine kleine dll erstellt um ds Programm zu testen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public void StartUp()
        {
            Console.WriteLine("Hi I am a plugin!");
        }
    }
}


Nun wenn ich die dll plugin.dll in das verzeichnis der exe kopiere und die exe ausführe, bekomme ich diesen Fehler:

Die Datei oder Assembly plugin.dll oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.

Erst dachte ich es würde an dem Pfad liegen und habe die plugin.dll in den Windows\System32 Ordner kopiert. Funktioniert immer noch nicht. Also einfach mal die mscorelib.dll per Load geladen und damit funktioniert es.

Hat einer von euch eine IDee woran es liegen kann?

Danke für jegliche Hilfe!

Mips

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 25.10.08 16:20 
LoadFile dürfte es eher treffen:
Zitat:
To load assemblies dynamically, the Assembly class provides the following static methods (Shared methods in Visual Basic). Assemblies are loaded into the application domain where the load operation occurs.

The recommended way to load assemblies is to use the Load method, which identifies the assembly to be loaded by its display name (for example, "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"). The search for the assembly follows the rules described in How the Runtime Locates Assemblies.

The ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods enable you to load an assembly for reflection, but not for execution. For example, an assembly that targets a 64-bit platform can be examined by code that is running on a 32-bit platform.

The LoadFile and LoadFrom methods are provided for rare scenarios in which an assembly must be identified by path.


PS: Es gibt schon einige mächtige Plugin-Frameworks, falls du das Rad nicht zweimal erfinden willst.

_________________
>λ=
Mips Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: So 26.10.08 14:25 
Hallo zusammen,

danke für die schnelle Antwort, LoadFile hat das Problem gelöst.

Danach bin ich heute auf ein ganz anderes Problem gestoßen zu dem ich bisher noch keine Antwort geunden habe und ich hoffe, dass ihr mir hier helfen könnt. Ich setzte VS.NET 2008 ein. Ich habe eine Projektmappe (solution) erstellt und in dieser Solution 3 Projekte.
Ein Projekt ist nur ein namespace (NR.DefinedInterface) , in dem ein interface enthalten ist.
Diesen Namespace möchte ich in den zwei anderen Projekten einbinden. Wenn ich jedoch nun den namespace einbinden möchte:
ausblenden Quelltext
1:
using NR.DefinedInterface;					

bekomme ich die Fehlermeldung:
Fehler 1 Der Typ- oder Namespacename "NR" konnte nicht gefunden werden. (Fehlt eine Using-Direktive oder ein Assemblyverweis?) C:\Dokumente und Einstellungen\Administrator\Eigene Dateien\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 5 7 ConsoleApplication1

Leider finde ich im Netz auch keine Informationen. Muss ich irgendwo den Inlcude Pfad anpassen, ala gcc?
Ich wollte es gerne so machen, wie ich später in diesem Video sah:
www.johnkoerner.com/...chitecture-in-C.html

Kann mir einer von euch weiterhelfen. Wäre klasse, danke!

Mips
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 26.10.08 14:26 
Hallo!

Bitte erstelle für eine neue Frage auch einen neuen Thread, damit man in einer Suche anhand des Titel erkennen kann, ob relevante Informationen enthalten sind. Danke! :-)

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Dieses Thema ist gesperrt, Du kannst keine Beiträge editieren oder beantworten.

Das Thema wurde von einem Team-Mitglied geschlossen. Wenn du mit der Schließung des Themas nicht einverstanden bist, kontaktiere bitte das Team.