Oppure

Loading
03/07/09 13:43
Linkinf22
Codice sorgente nell' applicazione

private void openFileDialog_FileOk(object sender, CancelEventArgs e)
{
string dllPath = openFileDialog.FileName;
Assembly AggiungiProgramma = Assembly.Load(dllPath);
Type ClasseDelProgrammaDaAggiungere = AggiungiProgramma.GetType"ClasseDelProgramma";);
MethodInfo InformazioniMetodo = ClasseDelProgrammaDaAggiungere.GetMethod("AggiungiIlProgramma";);
Object Instanza = AggiungiProgramma.CreateInstance(ClasseDelProgrammaDaAggiungere.Name);
InformazioniMetodo.Invoke(Instanza, new Object[] {tabunearth});
}

Codice sorgente della dll... Un po' lunghino

namespace Browser
{
public class ClasseDelProgramma
{
unearth.FrmPrincipale FormPrincipaleUnearth = new FrmPrincipale();

private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmPrincipale));
this.tabBrowser = new System.Windows.Forms.TabPage();
this.tabPagineWebBrowser = new System.Windows.Forms.TabControl();
this.schedaBrowser = new System.Windows.Forms.TabPage();
this.webBrowser = new System.Windows.Forms.WebBrowser();
this.toolStripBrowser = new System.Windows.Forms.ToolStrip();
this.tsbBrowserIndietro = new System.Windows.Forms.ToolStripButton();
this.tsbBrowserAvanti = new System.Windows.Forms.ToolStripButton();
this.tsbBrowserAddTab = new System.Windows.Forms.ToolStripButton();
this.tsbBrowserRemoveTab = new System.Windows.Forms.ToolStripButton();
this.tsbHome = new System.Windows.Forms.ToolStripButton();
this.tsbImpostazioniBrowser = new System.Windows.Forms.ToolStripButton();
this.btnBrowserVai = new System.Windows.Forms.Button();
this.tbxBrowser = new System.Windows.Forms.TextBox();
this.lblBrowser = new System.Windows.Forms.Label();
this.browserToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tabBrowser.SuspendLayout();
this.tabPagineWebBrowser.SuspendLayout();
this.schedaBrowser.SuspendLayout();
this.toolStripBrowser.SuspendLayout();
//
// tabBrowser
//
this.tabBrowser.BackColor = System.Drawing.Color.CornflowerBlue;
this.tabBrowser.Controls.Add(this.tabPagineWebBrowser);
this.tabBrowser.Controls.Add(this.toolStripBrowser);
this.tabBrowser.Controls.Add(this.btnBrowserVai);
this.tabBrowser.Controls.Add(this.tbxBrowser);
this.tabBrowser.Controls.Add(this.lblBrowser);
this.tabBrowser.Location = new System.Drawing.Point(4, 22);
this.tabBrowser.Name = "tabBrowser";
this.tabBrowser.Padding = new System.Windows.Forms.Padding(3);
this.tabBrowser.Size = new System.Drawing.Size(768, 521);
this.tabBrowser.TabIndex = 0;
this.tabBrowser.Text = "Browser";
//
// tabPagineWebBrowser
//
this.tabPagineWebBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabPagineWebBrowser.Controls.Add(this.schedaBrowser);
this.tabPagineWebBrowser.Location = new System.Drawing.Point(0, 63);
this.tabPagineWebBrowser.Name = "tabPagineWebBrowser";
this.tabPagineWebBrowser.SelectedIndex = 0;
this.tabPagineWebBrowser.Size = new System.Drawing.Size(772, 462);
this.tabPagineWebBrowser.TabIndex = 5;
//
// schedaBrowser
//
this.schedaBrowser.Controls.Add(this.webBrowser);
this.schedaBrowser.Location = new System.Drawing.Point(4, 22);
this.schedaBrowser.Name = "schedaBrowser";
this.schedaBrowser.Padding = new System.Windows.Forms.Padding(3);
this.schedaBrowser.Size = new System.Drawing.Size(764, 436);
this.schedaBrowser.TabIndex = 0;
this.schedaBrowser.Text = "Scheda vuota";
this.schedaBrowser.UseVisualStyleBackColor = true;
//
// webBrowser
//
this.webBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser.Location = new System.Drawing.Point(3, 3);
this.webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser.Name = "webBrowser";
this.webBrowser.Size = new System.Drawing.Size(758, 430);
this.webBrowser.TabIndex = 0;
this.webBrowser.Url = new System.Uri("google.it";, System.UriKind.Absolute);
//
// toolStripBrowser
//
this.toolStripBrowser.BackColor = System.Drawing.Color.CornflowerBlue;
this.toolStripBrowser.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStripBrowser.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsbBrowserIndietro,
this.tsbBrowserAvanti,
this.tsbBrowserAddTab,
this.tsbBrowserRemoveTab,
this.tsbHome,
this.tsbImpostazioniBrowser});
this.toolStripBrowser.Location = new System.Drawing.Point(3, 3);
this.toolStripBrowser.Name = "toolStripBrowser";
this.toolStripBrowser.Size = new System.Drawing.Size(762, 25);
this.toolStripBrowser.TabIndex = 4;
this.toolStripBrowser.Text = "toolStrip1";
//
// tsbBrowserIndietro
//
this.tsbBrowserIndietro.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbBrowserIndietro.ImageTransparentColor = System.Drawing.Color.White;
this.tsbBrowserIndietro.Name = "tsbBrowserIndietro";
this.tsbBrowserIndietro.Size = new System.Drawing.Size(23, 22);
this.tsbBrowserIndietro.Text = "Indietro";
//
// tsbBrowserAvanti
//
this.tsbBrowserAvanti.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbBrowserAvanti.ImageTransparentColor = System.Drawing.Color.White;
this.tsbBrowserAvanti.Name = "tsbBrowserAvanti";
this.tsbBrowserAvanti.Size = new System.Drawing.Size(23, 22);
this.tsbBrowserAvanti.Text = "Avanti";
//
// tsbBrowserAddTab
//
this.tsbBrowserAddTab.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbBrowserAddTab.Image = ((System.Drawing.Image)(resources.GetObject("tsbBrowserAddTab.Image";)));
this.tsbBrowserAddTab.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbBrowserAddTab.Name = "tsbBrowserAddTab";
this.tsbBrowserAddTab.Size = new System.Drawing.Size(23, 22);
this.tsbBrowserAddTab.Text = "+";
//
// tsbBrowserRemoveTab
//
this.tsbBrowserRemoveTab.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbBrowserRemoveTab.Image = ((System.Drawing.Image)(resources.GetObject("tsbBrowserRemoveTab.Image";)));
this.tsbBrowserRemoveTab.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbBrowserRemoveTab.Name = "tsbBrowserRemoveTab";
this.tsbBrowserRemoveTab.Size = new System.Drawing.Size(23, 22);
this.tsbBrowserRemoveTab.Text = "-";
//
// tsbHome
//
this.tsbHome.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbHome.Image = ((System.Drawing.Image)(resources.GetObject("tsbHome.Image";)));
this.tsbHome.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbHome.Name = "tsbHome";
this.tsbHome.Size = new System.Drawing.Size(44, 22);
this.tsbHome.Text = "Home";
//
// tsbImpostazioniBrowser
//
this.tsbImpostazioniBrowser.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbImpostazioniBrowser.Image = ((System.Drawing.Image)(resources.GetObject("tsbImpostazioniBrowser.Image";)));
this.tsbImpostazioniBrowser.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbImpostazioniBrowser.Name = "tsbImpostazioniBrowser";
this.tsbImpostazioniBrowser.Size = new System.Drawing.Size(79, 22);
this.tsbImpostazioniBrowser.Text = "Impostazioni";
//
// btnBrowserVai
//
this.btnBrowserVai.Location = new System.Drawing.Point(287, 34);
this.btnBrowserVai.Name = "btnBrowserVai";
this.btnBrowserVai.Size = new System.Drawing.Size(40, 23);
this.btnBrowserVai.TabIndex = 3;
this.btnBrowserVai.Text = "Vai";
this.btnBrowserVai.UseVisualStyleBackColor = true;
//
// tbxBrowser
//
this.tbxBrowser.Location = new System.Drawing.Point(55, 34);
this.tbxBrowser.Name = "tbxBrowser";
this.tbxBrowser.Size = new System.Drawing.Size(226, 20);
this.tbxBrowser.TabIndex = 2;
//
// lblBrowser
//
this.lblBrowser.AutoSize = true;
this.lblBrowser.BackColor = System.Drawing.Color.Transparent;
this.lblBrowser.Location = new System.Drawing.Point(1, 37);
this.lblBrowser.Name = "lblBrowser";
this.lblBrowser.Size = new System.Drawing.Size(48, 13);
this.lblBrowser.TabIndex = 1;
this.lblBrowser.Text = "Indirizzo:";
}

private void AggiungiIlProgramma(TabControl tabunearth)
{
FormPrincipaleUnearth.tabunearth.TabPages.Add(tabBrowser);
}

private System.Windows.Forms.TabPage tabBrowser;
private System.Windows.Forms.Label lblBrowser;
private System.Windows.Forms.Button btnBrowserVai;
private System.Windows.Forms.TextBox tbxBrowser;
private System.Windows.Forms.ToolStrip toolStripBrowser;
private System.Windows.Forms.TabControl tabPagineWebBrowser;
private System.Windows.Forms.TabPage schedaBrowser;
public System.Windows.Forms.WebBrowser webBrowser;
private System.Windows.Forms.ToolStripButton tsbHome;
private System.Windows.Forms.ToolStripButton tsbBrowserIndietro;
private System.Windows.Forms.ToolStripButton tsbBrowserAvanti;
private System.Windows.Forms.ToolStripButton tsbBrowserAddTab;
private System.Windows.Forms.ToolStripButton tsbImpostazioniBrowser;
private System.Windows.Forms.ToolStripButton tsbBrowserRemoveTab;
private System.Windows.Forms.ToolStripMenuItem browserToolStripMenuItem;
}
}
aaa
04/07/09 6:58
Il Totem
private void AggiungiIlProgramma(TabControl tabunearth)
{
   FormPrincipaleUnearth.tabunearth.TabPages.Add(tabBrowser);
}


Scusa un attimo, ma cosa ce lo metti a fare l'argomento se poi non lo usi? E poi come fai a riferirti a FormPrincipale se questo codice è nella dll e il form nell'eseguibile? Non hai capito cosa intendevo io?
private void AggiungiIlProgramma(TabControl tabunearth)
{
   tabunearth.TabPages.Add(tabBrowser);
}


P.S.: in italiano è Istanza :D
Ultima modifica effettuata da Il Totem 04/07/09 6:59
aaa
04/07/09 12:58
Linkinf22
Scusa ma ho provato a cambiare come mi hai detto te ma il problema rimane, se provassi ad utilizzare un eseguibile anziché una dll? Comunque ho corretto, ora c'è scritto istanza :D
Ultima modifica effettuata da Linkinf22 04/07/09 12:59
aaa
05/07/09 12:25
Il Totem
Ora che lo guardo meglio, dovrebbe darti un'eccezione di tipo NullReferenceException: il metodo di aggiunta è dichiarato come private, e non si possono estrarre informazioni sui metodi privati, ma solo su quelli pubblici. Non ti dava questo errore?
aaa
05/07/09 12:56
Linkinf22
Allora... mi sono accorto che avviando l' applicazione in modalità debug quando clicko su apri nell' openFileDialog con selezionata la dll non accade niente, come se al pulsante apri non fosse assegnata nessuna funzione, non si chiude nemmeno la finestra dell' openFileDialog. Mentre se compilo il programma poi apro l' eseguibile dalla cartella release, dopo aver cliccato su apri nell' openFileDialog ovviamente con selezionata la dll mi esce questo errore:

Eccezione non gestita bla bla bla (per bla bla bla intendo la solita roba dell' errore dell' eccezione non gestita)

Impossibile caricare il file o l' assembly 'C:\Users\User\Documents\Visual Studio 2008\bla bla bla\Browser.dll' o una delle relative dipendenze. Il nome o la base di codice dell' assembly specificato non è valido. (Eccezione da HRESULT: 0x80131047).

Le informazioni su come richiamare il debug JIT (Just-In-Time) anziché questa finestra
sono riportate in fondo al messaggio.

************** Testo dell'eccezione **************
System.IO.FileLoadException: Impossibile caricare il file o l'assembly 'C:\Users\User\Documents\Visual Studio 2008\Projects\unearth\dll Browser\Browser\bin\Debug\Browser.dll' o una delle relative dipendenze. Il nome o la base di codice dell'assembly specificato non è valido. (Eccezione da HRESULT: 0x80131047)
Nome file: 'C:\Users\User\Documents\Visual Studio 2008\Projects\unearth\dll Browser\Browser\bin\Debug\Browser.dll'
in System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
in System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
in System.Reflection.Assembly.Load(String assemblyString)
in unearth.FrmPrincipale.openFileDialog_FileOk(Object sender, CancelEventArgs e)
in System.Windows.Forms.FileDialog.OnFileOk(CancelEventArgs e)
in System.Windows.Forms.FileDialog.HandleVistaFileOk(IFileDialog dialog)




************** Assembly caricati **************
mscorlib
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3074 (QFE.050727-3000)
Base di codice: C:/Windows/Microsoft.NET/Framework/v2.0.50727/…
----------------------------------------
mscorlib.resources
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3074 (QFE.050727-3000)
Base di codice: C:/Windows/Microsoft.NET/Framework/v2.0.50727/…
----------------------------------------
unearth
Versione assembly: 1.0.0.0
Versione Win32: 1.0.0.0
Base di codice: C:/Program%20Files/unearth/…
----------------------------------------
System.Windows.Forms
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3053 (netfxsp.050727-3000)
Base di codice: C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/…
----------------------------------------
System
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3053 (netfxsp.050727-3000)
Base di codice: C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/…
----------------------------------------
System.Drawing
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3053 (netfxsp.050727-3000)
Base di codice: C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/…
----------------------------------------
AxInterop.WMPLib
Versione assembly: 1.0.0.0
Versione Win32: 1.0.0.0
Base di codice: C:/Program%20Files/unearth/…
----------------------------------------
System.Windows.Forms.resources
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.3053 (netfxsp.050727-3000)
Base di codice: C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_it_b77a5c561934e089/…
----------------------------------------
Interop.WMPLib
Versione assembly: 1.0.0.0
Versione Win32: 1.0.0.0
Base di codice: C:/Program%20Files/unearth/…
----------------------------------------

************** Debug JIT **************
Per attivare il debug JIT, è necessario impostare il valore
jitDebugging nella sezione system.windows.forms del file di configurazione
dell'applicazione o del computer (machine.config).
L'applicazione inoltre deve essere compilata con il debug
attivato.

Ad esempio:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

Quando il debug JIT è attivato, tutte le eccezioni non gestite
vengono inviate al debugger JIT registrato nel computer,
anziché essere gestite da questa finestra di dialogo.

Comunque ora provo a mettere public e vedo che succede.
aaa
05/07/09 13:19
Linkinf22
Ho provato a mettere public ma non cambia nulla, l' errore esce lo stesso.
aaa