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

System.MethodAccessException when calling Key.Activate #52

Open
samirem opened this issue Jun 8, 2020 · 11 comments
Open

System.MethodAccessException when calling Key.Activate #52

samirem opened this issue Jun 8, 2020 · 11 comments
Assignees
Labels

Comments

@samirem
Copy link

samirem commented Jun 8, 2020

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.

@artemlos
Copy link
Contributor

artemlos commented Jun 9, 2020

@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
Copy link
Contributor

artemlos commented Jun 9, 2020

@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?

@samirem
Copy link
Author

samirem commented Jun 10, 2020

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.'

@artemlos
Copy link
Contributor

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

@samirem
Copy link
Author

samirem commented Jun 10, 2020

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.

@artemlos
Copy link
Contributor

@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?

@samirem
Copy link
Author

samirem commented Jun 10, 2020

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,
});

@artemlos
Copy link
Contributor

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

@samirem
Copy link
Author

samirem commented Jun 10, 2020

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
Copy link
Author

samirem commented Jun 12, 2020

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

@samirem
Copy link
Author

samirem commented Dec 5, 2020

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants