locked
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

    Question

  • Hello Friends,

    I'm new in C# coding although I have 6 years of VC++ experience.

    can someone help me in resolving the issue I’m facing as follows:

    I am working on an application File Synchronizer which sync files on different servers on the basis of time scheduled on the 'File Synchronizer'.

    I'm trying to set a schedule on the weekly basis and when I'm changing the time in case of weekly synchronization it is crashing with the error as follows:

    An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
    Additional information: Exception has been thrown by the target of an invocation.

    Crashing point it shows on the line of code

    this.syncNotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("syncNotifyIcon.Icon")));

    or

    this
    .Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

    in the function InitializeComponent().

    I have had verified the icon for the application $this.Icon in the resource file etc too but did not get any clue. What may be the possibilities of such error and ways to correct it.

    or if you need more information please let me know.


    Thanks in advance!!
    Regards
    Shiv

    Tuesday, June 23, 2009 10:22 AM

Answers

  • Did you set the properties for your icon to Embedded Resource?

    After that you can get the Icon by using the following C# code.

    Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Filename.ico"));
    • Marked as answer by Bin-ze Zhao Saturday, June 27, 2009 7:38 AM
    Tuesday, June 23, 2009 3:25 PM
  • Also, if you added this icon within the resources window on the properties pages, you could access it much easier like this:

    <assemblyName>.Properties.Resources.syncNotifyIcon;

    Where the <assemblyName> is the name of your assembly and syncNotifyIcon is the name of your icon.  The IDE generates some C# code for you automatically to access resources if you use the resource tab of the properties pages.
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    • Marked as answer by Bin-ze Zhao Saturday, June 27, 2009 7:38 AM
    Tuesday, June 23, 2009 3:28 PM

All replies

  • Did you set the properties for your icon to Embedded Resource?

    After that you can get the Icon by using the following C# code.

    Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Filename.ico"));
    • Marked as answer by Bin-ze Zhao Saturday, June 27, 2009 7:38 AM
    Tuesday, June 23, 2009 3:25 PM
  • Also, if you added this icon within the resources window on the properties pages, you could access it much easier like this:

    <assemblyName>.Properties.Resources.syncNotifyIcon;

    Where the <assemblyName> is the name of your assembly and syncNotifyIcon is the name of your icon.  The IDE generates some C# code for you automatically to access resources if you use the resource tab of the properties pages.
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    • Marked as answer by Bin-ze Zhao Saturday, June 27, 2009 7:38 AM
    Tuesday, June 23, 2009 3:28 PM