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

VariableLengthInlineArray - VS2019 - CS8170 and CS8347 #1251

Open
RFBomb opened this issue Aug 1, 2024 · 0 comments
Open

VariableLengthInlineArray - VS2019 - CS8170 and CS8347 #1251

RFBomb opened this issue Aug 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@RFBomb
Copy link

RFBomb commented Aug 1, 2024

Actual behavior

I'm making this post in case the dev team wants to review Visual Studio 2019 compatibility with this generator.
This generator has absolute no issues for this particular problem when I ran it in VS2022.
( Earlier in development, I had an issue where tests passed in VS2022, and failed in VS2019 when calling CopyFileEx, so I finished development in 2022, and was about to re-test in 2019 when this stopped me. )

image

Expected behavior

The generator should work for either studio.

Repro steps

This was working without issue (and passing unit tests) when compiled in VS2022.

  • Open project up in VS2019
  • Clean Solution
  • Trimmed the target frameworks down to net48 and net5.0 for targeted testing (this was done to all projects in the repo)
  • Build >> Error

For what its worth, I was able to compile and pass the tests I was concerned with after downgrading to CSWin32 v0.3.49-beta
( I did have to whip up a quick extension method fix in RoboSharp.Extensions.SymbolicLinkSupport.SymbolicLink)

private static Span<char> AsSpan(this MSWin.Wdk.__char_1 ch, int length)
        {
#if NETFRAMEWORK
            Span<char> r = new char[length];
            ch.CopyTo(r, length);
            return r;
#else
            return ch.AsSpan();
#endif
        }

this brief workaround makes sense, as VariableLengthInlineArray did not exist in v0.3.49-beta

  1. NativeMethods.txt content:
// IFileCopiers
CopyFileEx
MoveFileWithProgressW

// Symbolic Links
CreateSymbolicLink
CreateFile
DeviceIoControl
GetFinalPathNameByHandle 
PathRelativePathToW
GENERIC_ACCESS_RIGHTS
IO_REPARSE_TAG_SYMLINK
IO_REPARSE_TAG_MOUNT_POINT
FSCTL_GET_REPARSE_POINT
MAXIMUM_REPARSE_DATA_BUFFER_SIZE
MAX_PATH
REPARSE_DATA_BUFFER
SYMLINK_FLAG_RELATIVE
WIN32_ERROR
  1. NativeMethods.json content (if present): N/A

  2. Any of your own code that should be shared?

Link to the github repo : https://github.com/RFBomb/RoboSharp/tree/AsyncCopy

relevant portions of the CSProj file:

  <TargetFrameworks>
          net462;
          net48;
          netstandard2.0;
          netstandard2.1;
          netcoreapp3.1;
          net5.0;
          net6.0;   // Removed when opened in VS2019
          net8.0;   // Removed when opened in VS2019
      </TargetFrameworks>
  <NetFrameworkRegex><![CDATA[^net((4[5-8][0-2]?)|(.*2.0))$]]></NetFrameworkRegex>

<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>

<!-- Conditional Target Requirements -->
    <Choose>
        <!-- NetFramework | NetStandard 2.0 -->
        <When Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '$(NetFrameworkRegex)'))">
            <PropertyGroup>
                <langversion>9</langversion>
            </PropertyGroup>
            <ItemGroup>
                <PackageReference Include="System.Memory" Version="4.5.5" />
            </ItemGroup>
        </When>
        <!-- NetStandard 2.1 -->
        <When Condition=" '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netcoreapp3.1'">
            <PropertyGroup>
                <langversion>9</langversion>
            </PropertyGroup>
        </When>

        <!-- NetCoreApp | .Net5+ -->
        <Otherwise>
        </Otherwise>
    </Choose>
   

Generated Code:

namespace Windows.Win32
{
	internal struct VariableLengthInlineArray<T>
where T : unmanaged
	{
		internal T e0;


		internal ref T this[int index]
		{
						[UnscopedRef]
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref Unsafe.Add(ref this.e0, index);
		}


		[UnscopedRef]
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Span<T> AsSpan(int length)

		{
unsafe

			{
				fixed (void* p = &this.e0)
				{
					return new Span<T>(p, length);
				}
			}
		}
	}
}

Context

  • CsWin32 version: [0.3.106]
  • Win32Metadata version (if explicitly set by project):
  • Target Framework: Net48, Net5
  • LangVersion 9
@RFBomb RFBomb added the bug Something isn't working label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant