Deploying Web Part error "THE GIVEN ASSEMBLY NAME OR CODEBASE IS INVALID".

Posted by Sina under SharePoint on 3/23/2011 | Points: 10 | Views : 2456 | Status : [Member] | Replies : 1
I am facing a problem in using a web part on the SP site.I am encountering the same error for 2 different types of web parts built by me.:
1.)a user control web part that has as user control an .ascx that displays contents of a database table in a gridview (on the webpage)
2.) a simple calculator web part that adds/subtracts two numbers and shows the result.

These are the web parts i created. Build was successful. I shall enumerate the steps done by me during the creation of calculator web part:
1.Created a new webpart project in the name 'Calculator'
2.Renamed the .cs,.webpart,.xml parts of the solution to MyCalculator.cs, MyCalculator.webpart,MyCalculator.xml
3.Coding in .cs
4.Signing: .snk
5.Build: successful
6.Put the assembly in GAC
7.Run->inetmgr->chose my website, the corresponding web.config file and added safe control
8.wpcatalog->edited webpart (type,version.publickeytoken etc)
9. iisreset

Next when i take my sharepoint site and try to add the webpart, i can view my web part but while adding it, i get the error "THE GIVEN ASSEMBLY NAME OR CODEBASE IS INVALID".

My calculator code is below for reference:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace Calculator
{
[Guid("81583438-9dab-4e95-aaf9-70cb946bed64")]
public class MyCalculator : System.Web.UI.WebControls.WebParts.WebPart
{

TextBox textbox1, textbox2, textresult;
Button add, sub;


public MyCalculator()
{

}

protected override void CreateChildControls()
{

textbox1= new TextBox ();
textbox2= new TextBox ();
textresult=new TextBox ();
add=new Button ();
sub=new Button ();
textresult.ReadOnly=true;
add.Text="+";
sub.Text="-";
add.Click +=new EventHandler(add_Click);
sub.Click +=new EventHandler(sub_Click);
this.Controls.Add(textbox1);
this.Controls.Add(new LiteralControl("<br>"));
this.Controls.Add(textbox2);
this.Controls.Add(new LiteralControl("<br>"));
this.Controls.Add(add);
this.Controls.Add(sub);
this.Controls.Add(new LiteralControl("<br>"));
this.Controls.Add(textresult);


}

void add_Click(object sender, EventArgs e)
{
int a = int.Parse(textbox1.Text);
int b = int.Parse(textbox2.Text);
int c = a + b;
textresult.Text = c.ToString();
}
void sub_Click(object sender, EventArgs e)
{
int a = int.Parse(textbox1.Text);
int b = int.Parse(textbox2.Text);
int c = a - b;
textresult.Text = c.ToString();
}


}
}




Please help me troubleshoot this issue. I couldnt find a valid solution to my problem to the sites i checked for the same error.

@Sina


Responses

Posted by: Rahuljgosavi on: 3/23/2011 [Member] Starter | Points: 25

Up
0
Down
Try adding DLL into the bin directory of the site then try to populate the Webpart in the site.

Sina, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response