6

I have an Add-in project for excel. It works fine on my computer. But when I install it on a client machine it gives me the error message i mentioned.

  1. I have Published it using project-> properties-> publish.
  2. I have the 'Enable Just my code' ticked.
  3. I have cleared the ticks for 'thrown' and 'user-unhandled' for the 'file not found exception'
  4. I setup the project on the client with the "setup" file in the "publish" folder in my project folder.
  5. In publish-> prerequisites, I have these items ticked:

    .net framework sp1

    Microsoft .net framework 4

    Microsoft office 2007 primary interop assemblies

    Microsoft visual studio 2010 tools for office runtime

    Windows installer 4.5

  6. I'm 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; }
    }
    

    //************************************************************

  7. The 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;
    }
    
  8. The client machine has Excel 2010 installed on it.

  9. This is the line of code throwing the exception:

       excelApp = (Excel.Application) 
       System.Runtime.InteropServices.Marshal.GetActiveObject
       ("Excel.Application");
    
  10. What is weird is that it works when I follow the following steps: Run it on the client and get an exception. Run it on my own PC (where no exception occurs). Press the add-in button on the Excel ribbon I made, on the client machine's application AND THIS TIME I DON'T GET ANY EXCEPTION!! I checked it so many times. Every time I follow this order it works fine!

11. This is the stack trace of the exception

Thanks a lot in advance.

Edit: 12. My application works like this: The first time user clicks on my button on the ribbon, the login form appears, and if he is authorized the form he has asked for appears. The next times just the asked form appears. and the exception happens JUST the first time clicks. here is my code for that: (No exception occurs in the last line, but that's not the case with 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();
Fatima
  • 869
  • 10
  • 35
  • @Iravanchi Does the event-log on the malfunctioning client provide any details about what assembly couldn't be loaded? – J. Tihon Dec 08 '11 at 09:59
  • @J.Tihon I'm not sure, I have to check. I will post here when I did so. – Iravanchi Dec 08 '11 at 11:13
  • @J.Tihon There's an error logged during the installation of the published package, but it is related to .NET framework check. It's weird though, because exactly the same .NET framework version is already installed. Even I checked the .NET framework version on the development machine and deployment machine and they are the same, but the issue does not occur in the development machine. And I don't think it can be a framework installation issue because the application works some of the times. If the framework isn't present, it shouldn't work at all. – Iravanchi Dec 10 '11 at 12:07
  • possible duplicate of [XmlSerializer giving FileNotFoundException at constructor](http://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor) – Mark Rotteveel Aug 01 '14 at 14:17

5 Answers5

2

It's wee bit confusing looking just at the code spinets but from the title of the question I can guess that you have a problem with dynamic creation of serialization assembly (security issue or partial trust issue). You can try turning "Generate serialization assembly" in your Addin dll to Off by going to project properties / Build and selecting Off from the list.

Petar Vučetin
  • 3,555
  • 2
  • 22
  • 31
  • Yes, the issue is related to an assembly that is being generated by the application. But the weird thing is that it works "some" of the times, and even when it doesn't, if you "insist", it starts working! So my best guess is some threading issue that means someone is trying to load the assembly before it is actually created on another thread. – Iravanchi Dec 14 '11 at 06:23
  • You are a genius! I've been dealing with this for days. Thanks a lot. I really appreciate all the help. – Fatima Dec 17 '11 at 11:29
  • Thanks. I am far away from genius :)... had to deal with this stuff before. – Petar Vučetin Dec 31 '11 at 18:31
0

Try

project > Properties > Build tab > Generate serialization assembly > set Off

0

Did you include a reference to System.Runtime.Serialization?

Lucas B
  • 11,793
  • 5
  • 37
  • 50
0

Are you sure the client has .NET 4.0 installed?

RailRhoad
  • 2,128
  • 2
  • 25
  • 39
0

I've never done Excel addins, but I've created a few Visual Studio extensions and the error reminds me at the time, where I mixed up the registry paths for the extensions. For VS there are two paths in the registry to consider, one for 64bit and one for 32bit.

Have you checked the registry?

http://msdn.microsoft.com/de-de/library/bb386106(VS.90).aspx

Core_F
  • 3,372
  • 3
  • 30
  • 53