phalanger

Using System.Reflection and resources in Phalanger


I need to embed some resource in a pure compiled dll written in php using phalanger. These are txt files tha I set in visual studio as "Embedded Resource".

My problem is that I cannot use the Assembly class to get the resource using GetManifestResourceStream.

I tried code like this: use System\Reflection\Assembly

$asm = Assembly::GetExecutingAssembly(); //this gives me mscorlib instead of my dll
$str = $asm->GetManifestResourceStream("name");

My question is: how do I get access to embedded resources in phalanger? Many thanks


Solution

  • I'm not sure, why Assembly::GetExecutingAssembly() returns an incorrect value. Anyway to workaround the $asm value, use following code:

    $MyType = CLRTypeOf MyProgram;
    $asm = $MyType->Assembly;
    

    Then you can access embedded resources as you posted

    $asm->GetManifestResourceStream("TextFile1.txt");
    

    or you can include standard resource file (.resx) into your project, and use \System\Resources\ResourceManager

    $this->manager = new \System\Resources\ResourceManager("",$asm);
    $this->manager->GetObject("String1",null);
    

    Just note, currently there can be just one .resx within Phalanger project