Using Dictionary Class type in C#

John 511 Reputation points
2023-07-04T20:51:32.6333333+00:00

I am having issues with using the Dictionary class type after declaring a parameter.

It resulted in a null value error when it was compiled.

Can anyone fix this?

using System; using System.Windows.Forms; using Microsoft.Office.Interop.Word; using System.Collections.Generic;    namespace Word_Doc_002 {     public partial class ThisDocument     {          Dictionary dictionWord;                            private void ThisDocument_Startup(object sender, System.EventArgs e)         {             dictionWord.Application.CheckSpelling("big", WdDictionaryType.wdSpelling); //Compile time error. dictionWord was Null.          }          private void ThisDocument_Shutdown(object sender, System.EventArgs e)         {         }          #region VSTO Designer generated code          /// <summary>         /// Required method for Designer support - do not modify         /// the contents of this method with the code editor.         /// </summary>         private void InternalStartup()         {             this.Startup += new System.EventHandler(ThisDocument_Startup);             this.Shutdown += new System.EventHandler(ThisDocument_Shutdown);         }          #endregion     } } 
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Hui Liu-MSFT 48,706 Reputation points Microsoft External Staff
    2023-07-05T07:36:47.5666667+00:00

    Hi,@John.Welcome Microsoft Q&A. The Dictionary object being null and resulting in a "Object reference not set to an instance of an object" error. Dictionary objects that represent custom dictionaries are members of the Dictionaries collection.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 81,976 Reputation points Volunteer Moderator
    2023-07-04T22:17:30.0033333+00:00

    don't see any code to initial dictionWord to any value, so its null.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.