Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeInitializationException and InvalidCastException thrown when calling LithnetRMA from an execution controller #141

Closed
johnyukloud opened this issue Feb 13, 2018 · 4 comments

Comments

@johnyukloud
Copy link

johnyukloud commented Feb 13, 2018

When I invoke Lithnet Resource Management PS from MA executor, it would fail on

Set-ResourceManagementClient -BaseAddress "http://localhost:5725";

there is error in the application eventlog about System.TypeInitializationException: The type initializer for 'Lithnet.ResourceManagement.Client.ResourceManagementClient' threw an exception.

Seems it is not able to access the configure file when executed from the MA executor.

The code I executed as follow:

function ExecutionComplete
{
	param([Lithnet.Miiserver.Client.RunDetails]$lastRunDetails)
        
	# If the run was an import an a change was made, create the MACD report
	foreach ($step in $lastRunDetails.StepDetails)
	{
		if ($step.StepDefinition.Type -eq 'FullImport'){		
			Set-ResourceManagementClient -BaseAddress "http://localhost:5725";
			
			$terminatedPortalUsers = Search-Resources -Xpath "/Person[(EmployeeEndDate > op:subtract-dayTimeDuration-from-dateTime(fn:current-dateTime(), xs:dayTimeDuration('P1D'))) and (EmployeeEndDate < fn:current-dateTime())]" -AttributesToGet @("AccountName","EmployeeEndDate","EmployeeID")

			$terminatedPortalUsers | Export-Csv "C:\temp\test1.txt" -notype
			
			$psons = Get-MVObject -ObjectType person
			$psons | Export-Csv "C:\temp\test2.txt" -notype
		}
	}
}

The error in the eventlog as below:

Ascender SQL MA: ExecutionComplete handler threw an exception
System.ApplicationException: The PowerShell script encountered an error
at ExecutionComplete, : line 20
System.TypeInitializationException: The type initializer for 'Lithnet.ResourceManagement.Client.ResourceManagementClient' threw an exception. ---> System.InvalidCastException: [A]Lithnet.ResourceManagement.Client.ClientConfigurationSection cannot be cast to [B]Lithnet.ResourceManagement.Client.ClientConfigurationSection. Type A originates from 'Lithnet.ResourceManagement.Client, Version=1.0.6297.14599, Culture=neutral, PublicKeyToken=bd0636700c1e2538' in the context 'LoadNeither' in a byte array. Type B originates from 'Lithnet.ResourceManagement.Client, Version=1.0.6435.24336, Culture=neutral, PublicKeyToken=bd0636700c1e2538' in the context 'LoadFrom' at location 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\LithnetRMA\Lithnet.ResourceManagement.Client.dll'.
at Lithnet.ResourceManagement.Client.ClientConfigurationSection.GetConfiguration()
at Lithnet.ResourceManagement.Client.ResourceManagementClient..cctor()

what is the proper way to execute Lithnet Resource Management PS from MA executor from the Executor MA?

I have tried to wrap around the call inside a script block, it works but the Get-MVObject would fail, it would return

The Synchronization Service Manager service has stopped.

when the Synchronization Service Manager service is actually running.

@ryannewington
Copy link
Member

@johnyukloud this is definitely a bug, but a complex one to solve. I'll look to resolve this in v2. In the mean time, the workaround would be to launch a new instance of PowerShell to run the fim service query such as shown in this example https://stackoverflow.com/questions/23237473/powershell-launch-script-in-new-instance

You seem to be referencing another issue with Get-MVObject. That is from a different PowerShell module. Can you provide more information about the context of the issue you are having there?

@ryannewington
Copy link
Member

@johnyukloud I'm working on the fix for this, but I've got a cleaner workaround you can use in the mean time. Edit the Lithnet.Miiserver.AutoSync.exe.config file and remove the following two lines

<section name="lithnetResourceManagementClient" type="Lithnet.ResourceManagement.Client.ClientConfigurationSection, Lithnet.ResourceManagement.Client"/>

and

<lithnetResourceManagementClient resourceManagementServiceBaseAddress="http://localhost:5725"/>

This will prevent the error you are seeing. These lines are not needed for AutoSync or the PowerShell module to work.

ryannewington added a commit to lithnet/resourcemanagement-client that referenced this issue Feb 17, 2018
…zing the ResourceManagementClient when two different versions of the assembly had been loaded into the same AppDomain lithnet/miis-autosync#141
ryannewington added a commit to lithnet/resourcemanagement-powershell that referenced this issue Feb 17, 2018
…zing the ResourceManagementClient when two different versions of the assembly had been loaded into the same AppDomain lithnet/miis-autosync#141
ryannewington added a commit that referenced this issue Feb 17, 2018
Updates RMC library to fix issue #141
@ryannewington
Copy link
Member

@johnyukloud i'm marking this issue as done. You can apply the workaround above, or install the latest version of LithnetRMA from https://github.com/lithnet/resourcemanagement-powershell/releases/tag/v1.0.6623

If you are still having issues with Get-MVObject, please open a new issue, and we work on that one separately, as it is unrelated to what is going on here.

@ryannewington ryannewington changed the title Unable to call LithnetRMA from MA executor - System.TypeInitializationException: The type initializer for 'Lithnet.ResourceManagement.Client.ResourceManagementClient' threw an exception TypeInitializationException and InvalidCastException thrown when calling LithnetRMA from an execution controller Feb 17, 2018
@johnyukloud
Copy link
Author

Great! Thanks Ryan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants