Unable to load embedded resources

Issue #180 resolved
Former user created an issue

When working with windows forms inside visual studio 2017 build 15.9.16 when I add a local resource and map an element to that resource it fails to load. I created a form and under Form1.ps1 I can see and edit Form1.resx which contains my imported resources. When I look in Form1.designer.ps1 I can see this line: 'Import-LocalizedData -BaseDirectory $PSScriptRoot -FileName 'Form1.resources.psd1' -BindingVariable resources' and when I go look in Form1.resources.psd1 the file is completely empty.

The ability to design interfaces inside of visual studio and bundle them into self contained packages was the entire reason our company purchased your software. I am hopeful this gets patched soon.

PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Comments (3)

  1. Erik Smith

    You can work around this by creating a helper script that loads your form.

    [void][System.Reflection.Assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    [void][System.Reflection.Assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    
    $resourceFile = <relative path to resource file>
    $formFile = <relative path to resource file>
    
    $resourceObjects = New-Object -TypeName 'System.Resources.ResXResourceSet' -ArgumentList (Join-Path $PSScriptRoot $resourceFile)
    [hashtable]$resources = @{}
    ForEach-Object -InputObject $resourceObjects {
        $key = $_.key.ToString()
        $resources[$key] = $_.value
    }
    
    . (Join-Path $PSScriptRoot $formFile )
    

    Then in <your form name>.designer.ps1 comment out the Import-LocalizedData line along with the two System.Reflection.Assembly lines at the top since they are now redundant. The downside to this work around is every time you make an edit using the form designer you need to re-comment these three lines. Technically you only need to comment our the Import-LocalizedData line.

  2. Daniel Rheault

    I have the same issue but it is working in visual studio but not when I execute the .exe in the out folder

  3. Log in to comment