junian / Standard.Licensing

Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and MAUI / Xamarin products
https://junian.dev/Standard.Licensing/
MIT License
535 stars 120 forks source link

Embed Standard.Licensing.dll failed #24

Closed SonaBIMDev closed 1 year ago

SonaBIMDev commented 1 year ago

Hi. I'd like to embed Standard.Licensing.dll and Device.Id into an exe. I've added both dlls has references and put CopyLocal to false I've added Device.Id and Standard.Licensing.dll to a Directory called dll I've changed the property to RessourcesEmbeded And in Main app I've this

[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; Application.Run(new Frm_LicenseManager()); }

and this

`private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); AssemblyName assemblyName = new AssemblyName(args.Name);

        var path = assemblyName.Name + ".dll";
        if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);

        using (Stream stream = executingAssembly.GetManifestResourceStream(path))
        {
            if (stream == null) return null;

            var assemblyRawBytes = new byte[stream.Length];
            stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
            return Assembly.Load(assemblyRawBytes);
        }
    }`

in Frm_LicenseManager, I can do generate a deviceId , it works, But, when generate a license, I've got a crash!

`var dictionary = new Dictionary<string, string> { { "MachineId", _deviceId } };

            var license = Standard.Licensing.License.New()
            .As(LicenseType.Standard)
            .WithAdditionalAttributes(dictionary)
            .CreateAndSignWithPrivateKey(_publicKey, _productName);`
SonaBIMDev commented 1 year ago

I found it...

SonaBIMDev commented 1 year ago

I found it