Can you still load .NET assemblies inside your PowerShell script even if .NET Framework is not installed? It confuses me because C:\Windows\Microsoft.NET\Framework is there with folders from versions 1 to 4 in there. But if I look at Programs and Features, Microsoft .NET Framework is not installed in there.
I’m asking because in one of my environment where I have my script and .NET 4.0 is installed, it works fine. But in the environment where .NET framework is not installed but the assemblies are in there, it fails saying that it cannot find type System.Runtime.Serialization.Json.DataContractJsonSerializer. I have code which loaded the System.Runtime.Serialization assembly.
PowerShell doesn’t run without .NET. PowerShell itself is coded in .NET.
The “Program Files” location isn’t .NET. It’s usually supporting files and reference assemblies. It shouldn’t be necessary. “Programs and Features” also doesn’t necessarily list every version of .NET, because not all of them are optional. Non-optional versions aren’t usually listed.
Your problem is more likely that the machine has only an OLDER version of .NET - enough to run PowerShell, but without the JSON serializer stuff from a newer version.
You’re right .NET Framework is installed. And it’s the 4.5 version, which is the same as what I have in the other environment where the script is working. Now I’m not sure what’s causing the script to fail in this environment.
Your problem is that System.Runtime.Serialization.Json.DataContractJsonSerializer is in the System.Runtime.Serialization .NET namespace which is NOT loaded by default into PowerShell.
Try using Add-Type to load the assembly containing System.Runtime.Serialization.Json.DataContractJsonSerializer
I did this for both environment and the output file is the same. It’s just in the other environment, it’s giving me the error that i can’t find datacontractjsonserializer.