I have an add-in project for excel. It works fine on my computer. But when I install it on the client machine, it gives me the error message that I mentioned.
- I published it using project-> properties-> publish.
- I have a checkbox labeled "Include only my code."
- I cleared the ticks for the “abandoned” and “user-unhandled” for the “not found exceptions”
- I am setting up a project on the client with the “setup” file in the “publish” folder in the project folder.
In publish-> prerequisites, I have these elements:
.net framework sp1
Microsoft.net framework 4
Primary Prefabricated Assemblies for Microsoft Office 2007
Microsoft visual studio 2010 for office time
Windows Installer 4.5
I am using JSON. this is the code for my class:
[Serializable] [JsonObject(MemberSerialization.OptIn)] public class documentSchemaRestInfo { [System.Runtime.Serialization.DataMember] [JsonProperty] public double id { get; set; } [System.Runtime.Serialization.DataMember] [JsonProperty] public string name { get; set; } [System.Runtime.Serialization.DataMember] [JsonProperty] public string description { get; set; } [System.Runtime.Serialization.DataMember] [JsonProperty] public string[] fields { get; set; } }
// ************************************************ ************
Code that uses the class:
public List<DocumentField> getSchemaOfGroup(documentGroupPk groupPK) { List<DocumentField> result = new List<DocumentField>(); HttpWebRequest request = (HttpWebRequest)WebRequest. Create(ProxyFactory.baseAddress+"/services/rest/group/" + groupPK.id + "/schema"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); string responseBody = streamReader.ReadToEnd(); dynamic ds = ((dynamic)JsonConvert.DeserializeObject(responseBody)) .documentSchemaRestInfo; foreach (dynamic f in ds.fields) { result.Add(new DocumentField( f.name.ToString(),f.internalName.ToString(),false)); } return result; }
Excel 2010 is installed on the client computer.
This is a line of code that throws an exception:
excelApp = (Excel.Application) System.Runtime.InteropServices.Marshal.GetActiveObject ("Excel.Application");
What is strange is that it works when I follow these steps: Run it on the client and get an exception. Run it on my own computer (where the exception does not occur). Click the add-in button on the Excel ribbon that I made on the client machine application AND THIS TIME I DO NOT GET ANY EXCEPTION !! I checked it so many times. Every time I follow this order, it works great!
eleven. 
Thank you very much in advance.
Edit: 12. My application works as follows: The first time a user clicks on my button on the ribbon, a login form appears, and if he is authorized, the application that he asked appears. The next time only the requested form appears. and the exception occurs JUST for the first time. here is my code for this: (An exception does not occur on the last line, but this does not apply to the case with the 7th line)
1.//If there is no ticket, means we haven't had a successfull login yet.=> 2.// We should show the login form instead of groups form. 3.if (string.IsNullOrEmpty(ProxyFactory.ticket)) 4.{ 5. okOrCancel = new LoginForm().ShowDialog(); 6. if (okOrCancel == DialogResult.OK) 7. new GroupsForm().ShowDialog(); 8.} 9.//If the is a ticket, means we have had a successful login. 10.else 11. new GroupsForm().ShowDialog();
source share