Assembly.GetExecutingAssembly() is throwing a NullReferenceException

0

In the constructor method of my "Translator"-Class, i need to initialize a ResourceManager to access all the strings i later need. But as i try to get the current executing Assembly, it fails with System.NullReferenceException occurred HResult=0x80004003 Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. Source=MyStreamingPlayer

The following Code is my Class Constructor:

class Translator
{
    public Form[] FormsToTranslate { get; }
    ResourceManager rm;

    public Translator(Form form, string language)
    {
        FormsToTranslate[0] = form;
        Assembly asm = Assembly.GetExecutingAssembly();

        string resname = asm.GetName().Name + ".lang_" + language;
        rm = new ResourceManager(resname, asm);
    }
}

And Assembly asm = Assembly.GetExecutingAssembly(); being the line failing with the System.NullReferenceException. A few hours ago i made some changes, the following Code worked fine:

class Translator
{
    public Form FormToTranslate { get; set; }
    ResourceManager rm;

    public Translator(Form form, string language)
    {
        FormToTranslate = form;
        Assembly asm = Assembly.GetExecutingAssembly();
        string resname = asm.GetName().Name + ".lang_" + language;
        rm = new ResourceManager(resname, asm);
    }
}

I don't know what happened, but if i change this part back to what i had before, everything works fine. As far as i can see, i didn't change anything that could cause Assembly.GetExecutingAssembly() to break with a NullReferenceException.

c#
.net
visual-studio-2017
asked on Stack Overflow Feb 5, 2017 by MrElliwood • edited Feb 5, 2017 by MrElliwood

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0