cryptolens-dotnet icon indicating copy to clipboard operation
cryptolens-dotnet copied to clipboard

System.MethodAccessException when calling Key.Activate

Open samirem opened this issue 4 years ago • 11 comments

I'm trying to call Key.Activate, but I get the following exception:

System.MethodAccessException: 'Attempt by security transparent method 'SKM.V3.Methods.Helpers.GetPlatform()' to access security critical method 'System.Runtime.InteropServices.OSPlatform.get_Linux()' failed.

Assembly 'Cryptolens.Licensing, Version=4.0.25.1, Culture=neutral, PublicKeyToken=30182975912ff1ef' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.'

Running version 4.0.25.

I've tried mixing around with attributes such as [assembly: SecurityRules(SecurityRuleSet.Level2)] without any success so far.

samirem avatar Jun 08 '20 17:06 samirem

@samirem thanks for reporting this! I thought it was fixed in v4025 but the error still seems to persist. We are looking into a way to solve this.

artemlos avatar Jun 09 '20 07:06 artemlos

@samirem We released a pre-release as a part of PR #53. The compiled binaries can be downloaded here: https://github.com/Cryptolens/cryptolens-dotnet/releases/tag/v4.0.26

Could you please check if the error still persists?

artemlos avatar Jun 09 '20 10:06 artemlos

Hi!

Unfortunately, the problem still persists:

System.MethodAccessException: 'Attempt by security transparent method 'SKM.V3.Methods.Helpers.GetPlatform()' to access security critical method 'System.Runtime.InteropServices.OSPlatform.get_Linux()' failed.

Assembly 'Cryptolens.Licensing, Version=4.0.26.1, Culture=neutral, PublicKeyToken=30182975912ff1ef' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.'

samirem avatar Jun 10 '20 10:06 samirem

@samirem thanks the details. Quick question: could you please tell me a bit more about the platform and project type where this error occurs?

artemlos avatar Jun 10 '20 11:06 artemlos

Sure, I'm developing a desktop application in WPF. My solution includes 5 C# projects, 3 of them .NET Standard 2.0, and 2 of them .NET Framework 4.6.1 (1 WPF project and 1 Class Library).

The call to Key.Activate is done from the WPF (.NET 4.6.1) project.

samirem avatar Jun 10 '20 12:06 samirem

@samirem Thanks! I created a WPF C# project targeting .NET 4.6.1 on Windows 10 and tried it in both debug and release mode, but I'm not able to reproduce the error.

Could you please check if Helpers.GetMachineCodePI works better?

artemlos avatar Jun 10 '20 12:06 artemlos

I actually tried calling Key.Activate with an empty/random string instead of utilizing the Helpers.GetMachineCode/Helpers.GetMachineCodePI, and the error still occured.

See snippet below:

var result = Key.Activate(License.AccessToken, new ActivateModel
{
    Key = key,
    ProductId = License.ProductId,
    Sign = true,
    MachineCode = "0"/*Helpers.GetMachineCodePI(v: 2)*/,
    FloatingTimeInterval = 100,
    FriendlyName = Environment.MachineName,
});

samirem avatar Jun 10 '20 12:06 samirem

It's quite strange why it returns this error even if the machine code methods are not called. I have attached a sample WPF application, when you run it, do you get the same error?

App.zip

artemlos avatar Jun 10 '20 15:06 artemlos

I could run your sample app without any errors. It worked to call Key.Activate in your sample app too. I will see if I can find out why my app still does not work..

samirem avatar Jun 10 '20 15:06 samirem

Ok I have finally isolated the problem. It is related to having the nuget package ReactiveUI.Events.WPF installed.

samirem avatar Jun 12 '20 23:06 samirem

Hi @artemlos!

I wanted to check if this issue has been resolved for me, but unfortunately I cannot check due to my trial running out. Did try to contact you via email but haven't gotten any response yet 😄

samirem avatar Dec 05 '20 12:12 samirem