Skip to content

"The path is not of a legal form" after Visual Studio update #72

@sonomirco

Description

@sonomirco

Issue Description

After updating Visual Studio Pro, ILRepack.Lib.MSBuild.Task started throwing an ArgumentException with the message "The path is not of a legal form" during the assembly loading process. The error occurs specifically during the LoadPriorityObject<T> method execution.

Image

Environment

  • ILRepack.Lib.MSBuild.Task Version: [Your version - check your .csproj]
  • Visual Studio: Pro (recently updated)
  • Project Type: [Your project type - e.g., .NET Framework 4.8, .NET 6, etc.]
  • MSBuild Version: # ArgumentException: "The path is not of a legal form" after Visual Studio update

Error Details

System.AggregateException: 'One or more errors occurred.'
Inner Exception: ArgumentException: The path is not of a legal form.

Stack trace shows:
- System.IO.Path.LegacyNormalizePath(string, bool, int, bool) in Path.cs
- System.IO.Path.InternalGetDirectoryName(string) in Path.cs  
- Core.Authentication.Authenticator.InitializeApplication() in Authenticator.cs
- Core.Authentication.Authenticator.AcquireTokenAsync(System.IntPtr) in Authenticator.cs
- ToolboxGh.AssemblyPriority.PriorityLoad.AnonymousMethod__2_0() in AssemblyPriority.cs

ILRepack target

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<LibraryPath>$(PackageFolder)</LibraryPath>
		<LibraryPath Condition="'$(IsDynamo)' == 'true'">$(PackageFolder)bin\;@(DynamoDlls->'%(RelativeDir)')</LibraryPath>
	</PropertyGroup>
	
	<Target Name="ILRepacker" AfterTargets="DetermineILRepackInputsOutputs">
		<Message Text="Input assemblies: @(MergeAssemblies)" Importance="High" />
		<ILRepack
		  Parallel="true"
		  Internalize="true"
		  DebugInfo="true"
		  InputAssemblies="$(OutputAssembly);@(MergeAssemblies)"
		  LibraryPath="$(LibraryPath)"
		  TargetKind="Dll"
		  TargetPlatformDirectory="$(FrameworkDir)$(FrameworkVersion)"
		  OutputFile="$(OutputAssembly)"
		  Union="false"
		  CopyAttributes="false"
		  AllowMultiple="false"
		  Wildcards="false" />
	</Target>
</Project>

Additional Context

This issue appears to be related to how Visual Studio updates change path normalization or MSBuild path resolution. Similar issues have been reported with other MSBuild tasks after VS updates where path handling becomes more strict.

The error seems to occur in the authentication/assembly loading pipeline, suggesting the issue might be with how ILRepack resolves or normalizes file paths for assemblies being merged.

/// <summary>
/// Provides authentication functionality using Microsoft Identity Client (MSAL).
/// </summary>
public static class Authenticator
{
    private const string ClientId = AADConfig.ClientId;
    private static readonly string[] _scopes = { "User.Read" };

    /// <summary>
    /// Lazy-loaded instance of the authentication application.
    /// </summary>
    private static readonly Lazy<Task<IPublicClientApplication>> Application = new(InitializeApplication);

    /// <summary>
    /// Stores the authentication result of the current user session.
    /// </summary>
    public static AuthenticationResult User { get; set; } = null;

    /// <summary>
    /// Acquires an authentication token for the user.
    /// </summary>
    /// <param name="windowHandle">Handle to the application's main window for UI parenting.</param>
    /// <returns>A task that resolves to an <see cref="AuthenticationResult"/> containing the access token.</returns>
    public static async Task<AuthenticationResult> AcquireTokenAsync(IntPtr windowHandle)
    {
        var application = await Application.Value;

        // Retrieve the first available account from cache or use the OS account.
        var accountToLogin = (await application.GetAccountsAsync()).FirstOrDefault()
                             ?? PublicClientApplication.OperatingSystemAccount;

        try
        {
            // Attempt silent authentication using cached credentials.
            return await application.AcquireTokenSilent(_scopes, accountToLogin).ExecuteAsync();
        }
        catch (MsalUiRequiredException)
        {
            // Silent authentication failed (e.g., consent required, expired token, or password update).
            return await application.AcquireTokenInteractive(_scopes)
                .WithAccount(accountToLogin)
                .WithParentActivityOrWindow(windowHandle) // Required for correct UI parenting.
                .ExecuteAsync();
        }
    }

    /// <summary>
    /// Initializes the MSAL authentication application.
    /// </summary>
    private static async Task<IPublicClientApplication> InitializeApplication()
    {
        var pluginDirectory = Path.GetDirectoryName(typeof(Authenticator).Assembly.Location);

        var storageProperties = new StorageCreationPropertiesBuilder("msalcache.bin3", pluginDirectory)
            .Build();

        var application = PublicClientApplicationBuilder.Create(ClientId)
            .WithBroker(new BrokerOptions(BrokerOptions.OperatingSystems.Windows))
            .Build();

        // Configure token cache for persistent storage.
        // https://learn.microsoft.com/azure/active-directory/develop/msal-net-token-cache-serialization?tabs=desktop
        var cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties);
        cacheHelper.VerifyPersistence();
        cacheHelper.RegisterCache(application.UserTokenCache);

        return application;
    }

Request

Could you please help me solve this issue?
Otherwise, the best option I have is to downgrade Visual Studio Pro to the previous version.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions