I'm new to PowerShell. I'm trying to call a method of my custom C# dll. I failed due to multiple reasons.
Here is my code:
[System.Reflection.assembly]::LoadFile("E:\Mulukutla\Migration.dll")
$MyClass = New-Object DataMigration
$MyClass.MigrateData("$from\$name","$to\$name")
Exception calling "LoadFile" with "1" argument(s): "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. (Exception from HRESULT: 0x8013101B)" At E:\Mulukutla\myCodev1.ps1:3 char:39 + [System.Reflection.assembly]::LoadFile <<<< ("E:\Mulukutla\Migration.dll") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
New-Object : Cannot find type [DataMigration]: make sure the assembly containing this type is loaded. At E:\mulukutla\myCodev1.ps1:4 char:21 + $MyClass= New-Object <<<< DataMigration + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
Please help me by correcting, what is the mistake I'm doing?
invoke powershell from cmd by :
set COMPLUS_Version=v4.0.30319
powershell
or set the content of 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config' as follows(you may need to create this file if not exist):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
User contributions licensed under CC BY-SA 3.0