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

SemVerPS 1.1 on Windows PowerShell ends with Unable to find type [Semver.SemVersion] #8

Closed
ddemeyer opened this issue Aug 31, 2021 · 10 comments

Comments

@ddemeyer
Copy link

Below is Windows PowerShell 5.1 on a recent Windows 10 having .NET Framework 4.8 installed. SemVerPS 1.0 works.

PS C:\WINDOWS\system32> $PSVersionTable
Name                           Value                                                                                                                                                        
----                           -----                                                                                                                                                        
PSVersion                      5.1.19041.1151                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                      
BuildVersion                   10.0.19041.1151                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                                                      

PS C:\WINDOWS\system32> Uninstall-Module -Name SemVerPS
PS C:\WINDOWS\system32> Install-Module -Name SemVerPS -Repository PSGallery -MaximumVersion 1.0
PS C:\WINDOWS\system32> Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.0\CS\SemVersion.cs"
PS C:\WINDOWS\system32> ConvertTo-SemVer -Version "1.0.0+alpha"

Major      : 1
Minor      : 0
Patch      : 0
Prerelease : 
Build      : alpha

Below is a restarted Windows PowerShell 5.1 session on a recent Windows 10 having .NET Framework 4.8 installed. A new PowerShell process to avoid a lingering SemVer class/type loaded. SemVerPS 1.1 throws various errors

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value                                                                                                                                                        
----                           -----                                                                                                                                                        
PSVersion                      5.1.19041.1151                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                      
BuildVersion                   10.0.19041.1151                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                                                      

PS C:\WINDOWS\system32> Uninstall-Module -Name SemVerPS
PS C:\WINDOWS\system32> Install-Module -Name SemVerPS -Repository PSGallery 
PS C:\WINDOWS\system32> Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs"

Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(410) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(409) : 
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(410) : >>> #pragma warning disable CA1062 // Validate arguments of public methods
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(411) :             // If other is null, CompareByPrecedence() returns 1
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(413) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(412) :             return CompareComponent(Build, other.Build);
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(413) : >>> #pragma warning restore CA1062 // Validate arguments of public methods
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(414) :         }
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(558) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(557) : 
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(558) : >>> #pragma warning disable CA2225 // Operator overloads have named alternates
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(559) :         /// <summary>
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(568) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(567) :         public static implicit operator SemVersion(string version)
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(568) : >>> #pragma warning restore CA2225 // Operator overloads have named alternates
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(569) :         {
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(309) : 'Semver.SemVersion.Major.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(308) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(309) : >>>         public int Major { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(310) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(317) : 'Semver.SemVersion.Minor.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(316) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(317) : >>>         public int Minor { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(318) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(325) : 'Semver.SemVersion.Patch.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(324) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(325) : >>>         public int Patch { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(326) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(333) : 'Semver.SemVersion.Prerelease.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(332) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(333) : >>>         public string Prerelease { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(334) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(341) : 'Semver.SemVersion.Build.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(340) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(341) : >>>         public string Build { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(342) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : Cannot add type. Compilation errors occurred.
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
 

PS C:\WINDOWS\system32> ConvertTo-SemVer -Version "1.0.0+alpha"
Unable to find type [Semver.SemVersion].
At C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\Public\ConvertTo-SemVer.ps1:15 char:17
+     [OutputType([Semver.SemVersion[]])]
+                 ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Semver.SemVersion:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

For what it is worth, same machine the later code block works without problems on a PowerShell 7.1.4. But I think you remember why we need Windows PowerShell :-)

If you don't have time to look into it, can you share some highlights/problems on what changed between 1.0 and 1.1?
Thanks

@ddemeyer
Copy link
Author

Also wonder if compile into .NET Standard 2.0 (so .NET Framework 4.7.2+ and .NET (Core) 3.1) would not be an answer to the JIT *.CS file. Furthermore also noticed you changed you license from MIT to GPLv3...

@ddemeyer
Copy link
Author

ddemeyer commented Sep 9, 2021

Hi @Sarafian ... It could still be that I'm doing something wrong, but it is somewhat funny that SemVerPS new version 1.1 is not SemVer compatible for me/us - it breaks. Our workaround is Install-Module -Name SemVerPS -Repository PSGallery -MaximumVersion 1.0 for now...

@Sarafian
Copy link
Owner

Sarafian commented Sep 9, 2021

Hi Dave,
It was pull request #5. What changed was that the inclusion of new source code (the functionality is copied from the semver nuget project) and mostly fixed the code for pester 5 (had big changes). I think the Dev made changes towards the .net standard and those precompile directives might be causing problems.

I think I had done a quick check for Windows poweshell.

To my knowledge and confirmed with the pester tests the functionality didn't change, so you can use the previous version.

When I return, I'll take a look. The manifest files need to be more correct.

@Sarafian
Copy link
Owner

Sorry for the late response but you are indeed right.

The way the module works is that it uses the Add-Type to import the C# classes from the referenced NuGet repo. This happens in the SemVerPS.psm1. The cshart code from @maxhauser uses precompile directives but from what I know they are only considered during compile time. To address the .NET standard related changes from @maxhauser, I did what the compiler does and added the precompiler directive in the beginning of the Semver.cs which is also what broke compatibility with Windows PowerShell. With the last update, the imported c# was refactored and although the nuget package didn't break compatibility, the module which has a raw dependency to the code did.

I remember well and understand your dependency with Windows PowerShell and I would like the module to maintain backwards compatibility. But the module is actully a cmdlet wrapper around the functionality from @maxhauser's repo and as his code evolves towards core/standard so does the module move towards the core of powershell. So, I'm looking into how this could be possible.

I'm considering checking the powershell version and depending on the version add the directive or not. This would probably work. The problem I have is how does the AppVeyor CI make sure it works for Windows Powershell as well. I couldn't find much and therefore there is a new question on stackoverflow. Since you work with the Windows PowerShell maybe you have some insight to share.

In any case, I don't expect a fast response.

@ddemeyer
Copy link
Author

Thanks for looking into this @Sarafian! Technically it is already broken in v1.1 but y slightly increasing your platform support to .NET 4.7.2, you get access to NET Standard. So in turn you can offer a compiled version of the Semver.cs ... that is a way out.
For my favorite module ;-) I'm currently looking into https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners as free testing environments.

@Sarafian
Copy link
Owner

Sarafian commented Sep 21, 2021

I don't want to do the compiled version. For this I never embedded the nuget package or the dll.

Technically it is already broken in v1.1

That's where I broke it. 1.0 should be still good for your windows setup.

@Sarafian
Copy link
Owner

Sarafian commented Sep 22, 2021

@ddemeyer the new c# code won't work with or without the precompile directives. Unfortunately, following up on Max's code and keeping it simple (no compile) make the 1.1 version non-desktop version compatible. The only way to bring powershell desktop support is to load c# version code from when it worked but then the module updates are going to be gimic.

Unless you have a better suggestion, I'll create a new version with the manifest declaring the CompatiblePSEditions=@("Core")

That would mean that you need to update your dependency to v1.0 which still works in the desktop edition.

@ddemeyer
Copy link
Author

ddemeyer commented Sep 24, 2021

So summarized, are you thinking along these lines...

  1. V1.0 is Desktop and Core, works
  2. V1.1 is Desktop and Core with Max's latest code fixes but it broke for Desktop... so you could have the net48 and net5 C# code side by side and decide in the psm1 file on which runtime you are and which C# file to load... a patch release but latest version works again for everybody
  3. V2.0 could be Core only as you mention in Core edition only support #9 a breaking change for the future

Thanks for looking into this :-)

@Sarafian
Copy link
Owner

  1. V1.0 desktop edition. Core edition is broken I think for 7 or higher.
  2. V1.1 is broken for desktop edition.
  3. V2.0 only for core edition and respect some versioning rules. Unlist 1.1 as well.

Can't replace existing versions. Only unlist them.

I don't see how in a simple way it works for both editions. When you import a .net type it is not the same as a compiler and pre-compile directives are not defined or considered etc. I tried to fiddle with the code for the desktop edition and didn't import. Since this depends on a 3rt party's code, I don't want to have to troubleshoot it now or the future. Makes sense as the code projects are moving towards .net as well.

Functionally they are the same. Only the supported edition changes.

@Sarafian
Copy link
Owner

Sarafian commented Oct 6, 2021

Closing with

  • Use version 1.0 with PowerShell Desktop
  • Use version 2.0 with PowerShell Core with minimum version 7.0
  • Version 1.1 is now removed.

@Sarafian Sarafian closed this as completed Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants