BitArmory / ReCaptcha

:recycle: A friction-less C# HTTP verification client for Google's reCAPTCHA API.
https://www.google.com/recaptcha
Other
45 stars 11 forks source link

Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'XXX.Library.CustomIdentity' #6

Closed mar72vin closed 4 years ago

mar72vin commented 4 years ago

Version Information

Software Version(s)
NuGet Package 5.0
.NET Core? no
.NET Full Framework? 4.5
Windows OS? 2016
Visual Studio? 2019

What's the problem?

Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'XXX.Library.CustomIdentity' I am using custom forms authentication and regularly cast the Identity like this: (MyCustomIdentity)Csla.ApplicationContext.User.Identity).UserID);

Immediately after calling "var result = await captchaApi.Verify3Async(token, clientIp, secret);" all sessions are broken and cannot cast to MyCustomIdentity. Once this line is called every existing and new session breaks. Even if the user logs off and back on again the CustomIdentity never works as expected and the website needs to be restarted from IIS Manager.

This work perfectly fine in local IIS. I also have a few other websites using CSLA and this same nuget package and the others seem to work ok. I just can't work out what could cause the issue.

Would anyone have experience with something like this?

bchavez commented 4 years ago

The behavior you're describing is kind of reminiscent of the compiler linking one set of DLLs together when the line is included. And another set of DLLs when the line is excluded.

Things you might want to try:

Let me know what you find @mar72vin.

bchavez commented 4 years ago
bchavez commented 4 years ago

It's also possible, that if you are using a higher version of the .NET Framework on local development (say 4.6.1+), and your server is strictly (4.5), your development machine may be linking .NET Standard version of the library instead of the .NET Framework 4.5 version of the library.

image

image

bchavez commented 4 years ago

For convenience, here are the hashes for each TFM (BitArmory.ReCaptcha.dll v5.0.0):

   File: net45\BitArmory.ReCaptcha.dll
     MD5: 375f460242af27421b5b32c21538a8ce
   SHA-1: fd3f78b7a2e5335768a683e7e8c04f9f458f2f7d
 SHA-256: af8a9a77f6db53af5e5298b350ffd17832985cd35579cd381f356562a8f2da7d
 SHA-512: 7ee6d00242a2d5456031c4e8a9db186bfab09bd29770a1b14f0a98a3c93eb1d83f775b24b0123d6a71f18335eac705c085b543df7a9a0241762b6b8b20603a4d

    File: netstandard1.3\BitArmory.ReCaptcha.dll
     MD5: 1bbd54240e9cf5fa128762bb7496e10d
   SHA-1: fa62803b45239d8b6559fd8d382071d24a0d7c58
 SHA-256: 7b3dda0cfb8a342cdd3eb01177a58fc48f1014a20a71f6299e4bf807aa4e0643
 SHA-512: fa19ffc72c665268aca64aef7b775b4ab7125e15e1f5a88f4851806fc260558f77e6d66827152c58c3253d7e026c5da276354cca13afac9d4cde3d543480181b

    File: netstandard2.0\BitArmory.ReCaptcha.dll
     MD5: 6a723db85892137f6bb0e1f92c76b81b
   SHA-1: 48f51d34a9f68027f8edbc748f6002d1e36a5bc9
 SHA-256: 7ec81e81c334f6eac9dc75c2daff8c92fd3a6f28b4ad3e364baf936f3a3224a8
 SHA-512: f911392496e881aa0be337c7689927e8695c4a8c68c60329a50122a1ee509c58d2d2e826acce97d21b59b45f1acb09c679d9daccc28d32a81e5ebfce39181aad
bchavez commented 4 years ago

@mar72vin I'm going to close the issue now, please feel free to re-open the issue if you need more help or can provide more information about the issue. Thanks.

mar72vin commented 4 years ago

@bchavez, thanks for all your suggestions. I have tried them all now. I am still struggling to work out what could be causing the problem. In addition to the steps below I have also cleaned and rebuilt the solution.

1) Delete all bin and obj folders.

2) Clear Temporary ASP.NET Files I think it's here: ( I also did the 64 bit folders) c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

3) Double check the DLL version numbers of everything between your local dev and prod IIS directory.

4) Also, try to re-deploy the entire bin folder or website, not just the dll that changed.

5) I have confirmed that the dev machine is using .NET Framework 4.5. The .NET CLR Version of the apppool is v4.0.30319 which is the correct version for .NET Framework 4.5

bchavez commented 4 years ago

Hi @mar72vin, what TFM of the ReCaptcha dll are you using?

mar72vin commented 4 years ago

Hi @bchavez , I think you were right about the .NET framework mismatch. The web.config file on the production server was missing "targetFramework="4.5". I have added this now and it appears to be working as expected (I will monitor for a few days). So I'm not really sure what version the application was using to cause the broken behavior. Very strange. <httpRuntime targetFramework="4.5"/>

Thanks so much for your help!