[Bug] Unity Windows Standalone il2cpp: NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor
See original GitHub issueWhich Version of MSAL are you using ? MSAL 4.30
Platform net45 compiled with Unity Standalone il2cpp configuration
What authentication flow has the issue?
- Desktop / Mobile
- Interactive
- Integrated Windows Auth
- Username Password
- Device code flow (browserless)
- Web App
- Authorization code
- OBO
- Daemon App
- Service to Service calls
Other? - please describe;
Is this a new or existing app? c. This is a new app or experiment
Repro Create a Unity project and add MSAL authentication code similar to the below in a Unity component. Target Standalone and use the IL2CPP scripting backend.
private void BeforeAccessNotification(TokenCacheNotificationArgs args)
{
lock (FileLock)
{
args.TokenCache.DeserializeMsalV3(File.Exists(CacheFilePath)
? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), null, DataProtectionScope.CurrentUser)
: null);
}
}
private void AfterAccessNotification(TokenCacheNotificationArgs args)
{
// if the access operation resulted in a cache update
if (args.HasStateChanged)
{
lock (FileLock)
{
// reflect changes in the persistent store
File.WriteAllBytes(
CacheFilePath,
ProtectedData.Protect(
args.TokenCache.SerializeMsalV3(),
null,
DataProtectionScope.CurrentUser));
}
}
}
PublicClientApplicationBuilder builder = PublicClientApplicationBuilder.Create(clientId);
builder = builder.WithRedirectUri("http://localhost");
builder = builder.WithAuthority(AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount);
builder = builder.WithLogging(MsalLog, LogLevel.Error, true);
var PublicClientApp = builder.Build();
PublicClientApp.UserTokenCache.SetBeforeAccess(BeforeAccessNotification);
PublicClientApp.UserTokenCache.SetAfterAccess(AfterAccessNotification);
var authResult = await PublicClientApp.AcquireTokenSilent(scopes, Account).ExecuteAsync();
Expected behavior No dynamic code generation.
Actual behavior NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor
Possible Solution Building locally and removing the HAVE_CAS define seems to resolve the issue.
Additional context/ Logs / Screenshots Player.log
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
NotSupportedException (With log detail)
The first error (the one as runtime) indicates that IL2CPP does not support System.Reflection.Emit, which is expected.
Read more >Unity Json.net System.Reflection.Emit error in iOS
The error in this case is unrelated to managed code stripping or the link.xml file. This error occurs because the Newtonsoft JSON library...
Read more >Manual: Scripting restrictions
IL2CPP does not support reflection of the MarhsalAs and FieldOffset attributes at runtime. It does support these attributes at compile time. You should...
Read more >IL2CPP Overview
The IL2CPP backend converts MSIL (Microsoft Intermediate Language) code (for example, C# code in scripts) into C++ code, then uses the C++ code...
Read more >System.Reflection.Emit.DynamicMethod::.ctor_abc1329的 ...
NotSupportedException : System.Reflection.Emit. ... IL2CPP 不支持运行时代码生成(引自unity3d - Unity Json.net System.Reflection.Emit error in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bgavrilMS
I also ran a test for serializing / deserializing the token cache (I added a row in the table above). All in all, it does not seem to be bad. I think we can:
@henrik-me - thoughts?