Does the Visual Studio OneClick publisher change the byte array needed for RSA encryption?

Viewed 38

I'm trying to publish a COM add-in for Word and need to have a license file. I'm using Rhino Licensing and the file has no issues during debugging, but when using OneClick to publish the add-in the license is reported as no longer valid. Here is the code for the class I'm using to check the license:

using System;
using System.IO;
using Rhino.Licensing;

namespace Services.Licensing
{
    public class LicenseChecker
    {
        private static string PublicKeyPath;
        private static string LicensePath;

        public static bool LicenseIsValid(string licPath)
        {
            bool result = false;
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            String Root = Directory.GetCurrentDirectory();
            PublicKeyPath = Root + @"\Licensing\publicKey.xml";
            LicensePath = Root + @"\Licensing\license.xml";  //licPath;
            // not working on INSTALL, runs fine in debug

            try
            {
                var publicKey = File.ReadAllText(PublicKeyPath);

                //Throws an exception if license has been modified
                LicenseValidator validator = new LicenseValidator(publicKey, LicensePath);
                validator.AssertValidLicense();
            
                if (validator.ExpirationDate > DateTime.Now)
                {
                    result = true;
                }
            }
            catch
            { }

            return result;
        }
    }
}

I'm trying to bundle the license with the exe I'll be giving to a small testing group to save the testers unnecessary trouble managing the license and public key. Currently I have the (valid) license file and public key as embedded resources, set to "copy always."

I'm having the same issue when the license is not bundled with the published exe, but the public key is. When both files are left outside of the solution, there seems to be no problem. Could publishing the solution be changing the byte array of the public key or the license?

I'm using .Net Framework 4.7.2 and Visual Studio 2019.

1 Answers

After a lot of toying, the broad answer seems to be no, ClickOnce publishing does not affect the byte array.

The error seems to be occurring because the ClickOnce is not copying XML files into the Application Files folder it creates at all.

After pulling the licenses into a desktop folder and having the program call them from there, another class that uses XML files to load list items would not initialize, leading me to put Try{} around all functions that use pre-made XML files in my program. Each of these functions returned the Catch{}. I'm assuming that ClickOnce is too simplistic an installer to be used if you are trying to include many/any resource files, especially if they are XML.

Related