EndpointInitialization is not loading module functions for Content pages

I am not sure if this is an expected behavior:

Describe the Issue

It seems that the EndpointInitialization is not loading function from my module Core.AppBar.psm1 if the page is using -Content.

Startup.ps1

    $EndpointInitialization = New-UDEndpointInitialization -Module @(
        "$PSScriptRoot\Core\Core.AppBar.psm1",
    )

    $Pages = Get-ChildItem (Join-Path $PSScriptRoot 'Pages') -Recurse -File | ForEach-Object {
        & $_.FullName
    } 

    $Dashboard = New-UDDashboard -Title 'AdminCenter' -EndpointInitialization $EndpointInitialization -Pages $Pages 

Core.AppBar.psm1

function New-AppBar 
{
    param
    (
        [string]$Title
    )

    $Drawer = New-UDDrawer -Children {
        New-UDList -Children {
            New-UDListItem -Label "Test" -Children {
                New-UDListItem -Label "Temp" -OnClick { Invoke-UDRedirect -Url "/test/temp" }
            }
        }
    }
    
    New-UDAppbar -Children {
        New-UDElement -Tag 'div' -Content {$title}
    } -Drawer $Drawer
}

Page.psm1

New-UDPage -Url "/test/temp" -Icon home -Content {
    New-AppBar -Titel 'Temp'

    New-UDTextbox -Id 'txtTextfield' -Label 'First Name' 
}

Error:

New-UDPage : The term 'New-AppBar' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\augustin.ziegler\source\repos\Project\AdminPage\Pages\Test\TestTemp.ps1:1 char:1
+ New-UDPage -Url "/test/temp" -Icon home -Content {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SyntaxError: (UniversalDashboard.Models.Page:Page) [New-UDPage], CommandNotFoundException
    + FullyQualifiedErrorId : UniversalDashboard.Cmdlets.NewPageCommand
```

It is working with an Endpoint typed page.

#### Version Information
- **Operating System**: Win10
- **PowerShell Version**: 5.1.17763.1007
- **Universal Dashboard Version**: 3.0.0-beta1
- **UD Hosting Method**: Powershell


#### Additional context
Add any other context about the problem here.

This is expected with Content pages because they are statically defined at startup. Try adding this to the top of your Startup.ps1:

Import-Module    "$PSScriptRoot\Core\Core.AppBar.psm1"

Thank for note this down, but if I am using a “mixed mode” for Content and Endpoint both is required?

  1. Import-Module “$PSScriptRoot\Core\Core.AppBar.psm1”
  2. New-UDEndpointInitialization

If you remove EndpointInitialization all together and just import the module, I think it will work in both cases. By default, UD now loads all imported modules into the background runspaces: https://github.com/ironmansoftware/universal-dashboard/blob/master/src/UniversalDashboard/Services/UDRunspaceFactory.cs#L84

To sum up EndpointInitialization is not required in v3 anymore? :slight_smile:

Haha yea…it’s a lot less necessary. It’s still there to allow people to manage if they want but it shouldn’t be necessary.

1 Like

Great to know and love this removal :grinning: