none
Exception Has Been Thrown By The Target Of An Invocation - DLL File RRS feed

  • Question

  • I am running a task within a piece of engineering software. This task references a DLL file generated through Visual Studio.

    However whenever I run the task, I get the error 

    Exception Has Been Thrown By The Target Of An Invocation

    What's important is that the task works on later versions of the engineering software, but on older versions, I get the error.

    I believe this may be related to the NET Framework and/or references within the DLL file. 

    On the new version of the engineering software, I have the Target Framework set to .NET Framework 4 Client Profile and it works. However on the old version of the software, this stops the task from actually reading the DLL file. When I change it to .NET Framework 3.5 Client Profile it appears to load, but throws the invocation error above. 

    There's more info I can give, however based on what I've wrote here - can anyone assist?

    Note that my knowledge of C# and visual studio are minimal (I'm just trying to troubleshoot).

    Friday, August 2, 2019 11:20 AM

All replies

  • Most likely a function reacts differently on the older version of the Framework (3.5). It might be worth indicating which method is the culprit and may need you to use debugging techniques to know which method is causing the issue. 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, August 2, 2019 2:51 PM
    Moderator
  • Hi PolarAaron1991, 

    Thank you for posting here.

    According to your description, you can provide some details about your exception with which line of the code thrown the exception, and it will be beneficial for us to analyze your problem.

    Besides, I find a reference which shows the differences between .NET Frameworks 3.5 and 4.0.

    What are the major differences between NET Frameworks 3.5 and 4.0? [duplicate]

    I hope it can help you understand the problem.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 5, 2019 7:22 AM
  • Thanks, Karen.

    Unfortunately my knowledge of C# is minimal so it's difficult for me to add any debugging. I'll give it a try though. 

    Tuesday, August 13, 2019 2:11 PM
  • Hi Xingyu,

    The error doesn't really tell me the line it fails. 

    The code is similar to:

    [1] Loadfile('ExcelUtilities.DLL')

    [2] Using namespace 'ExcelUtilities.Namespace'

    [3] objectname = object Excelobject()

    [4] objectname.saveasexcelfile(filename, tab, table, update, 0, 0)

    The software appears to be loading the DLL. It's on line 4 that it fails, suggesting there someone going on within the DLL

    Tuesday, August 13, 2019 2:16 PM
  • Hi PolarAaron1991, 

    Thanks for your feedback.

    According to your description, I have two questions to confirm with you.

    >>This task references a DLL file generated through Visual Studio.

    What is this dll generated from? Visual Studio? C# code?

    >>Loadfile('ExcelUtilities.DLL')

    Is this dll developed on your own? Please provide more details about the dll.

    Besides, you can refer the following reference to debug your code in Visual Studio.

    Tutorial: Learn to debug C# code using Visual Studio

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 9:10 AM
  • Hi, 

    The DLL is generated in Visual Studio using C#. It was generated by someone else back in 2014.

    It works find on newer versions of the software, but when reverting back to an older version it throws the error. 

    I was just looking for general things to check - as it's very hard to explain the code without uploading something.

    I believe the older version of the software requires visual studio to be set to NET framework 3.5. However I noticed that when I change to 3.5, reference "Microsoft.CSharp" cannot be found. The solution still builds however, without any issues. Could this have something to do with it?
    Thursday, August 22, 2019 2:28 PM
  • Hi PolarAaron1991, 

    Thanks for your feedback, I have found two references:

    1. Reference Component Microsoft.CSharp could not be found
    2. The primary reference “Microsoft.CSharp”, which is a framework assembly, could not be resolved in the currently targeted framework

    I hope them can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 23, 2019 9:39 AM
  • Thanks Xingyu,

    I've had a look at those, and doesn't look like that's the problem. 

    I think I've ran out of ideas to try...

    Friday, August 23, 2019 12:20 PM
  • Hi Aaron,

    >>On the new version of the engineering software, I have the Target Framework set to .NET Framework 4 Client Profile and it works. However on the old version of the software, this stops the task from actually reading the DLL file. When I change it to .NET Framework 3.5 Client Profile it appears to load, but throws the invocation error above. <<

    OK, so you tried changing the Target Framework (which for the old version 4 won't load, but 3.5 appears to load) ... but are both compiled using the same Visual Studio version? Or are you using an older version of Visual Studio to compile the older software version? Could that be the problem?


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, August 25, 2019 1:51 AM
    Moderator
  • Hi Bonnie,

    Yes both were compiled using VS 2019.

    Could a different version cause an issue - and if so, how? We used to run the old version years ago. Back then, it would have been a different version of Visual Studio used to generate the DLL.

    We think it could be related to reference Microsoft.Office.Interop.Excel

    We currently run Office 365. Although it would have been Office 2010 we were running back when it was working. Could this be the issue?

    Monday, August 26, 2019 8:02 AM
  • Following from this - I ran the function on a Windows 7 machine, and it worked! The version of Excel appeared to be the same on that machine as on mine. 

    Does anyone have any ideas why this might be?

    What appears to be causing the issue is Windows 10 and (potentially) Microsoft.Office.Interop.Excel

    Monday, August 26, 2019 2:35 PM
  • Hi Aaron,

    I think that you're probably going down the right path ... the issue probably *does* have something to do with older vs newer versions of Office … but, unfortunately, I don't have any experience at all with Office Interop. Hopefully someone else can chime in with some ideas.


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Monday, August 26, 2019 4:03 PM
    Moderator
  • Hi PolarAaron1991,

    According to your description, I suggest you ask your question in Excel for Developers forum for more help.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 27, 2019 7:20 AM