Last post Feb 19, 2019 01:15 AM by Ackerly Xu
Feb 17, 2019 07:33 AM|dileep Sanker|LINK
I have asp.net Ajax application. I have a load balance server A,B and C.I have just copied the entire project to IIS virtual directory path.
When my application is working fine if my load balance server is on A or C. but if my application on Load balance server B, getting an InvalidCastException , and the error details as
System.InvalidCastException: [A]ProfileCommon cannot be cast to [B]ProfileCommon. Type A originates from 'App_Code.gerhjby9, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary
ASP.NET Files\site1\72113dc4\e9d65023\App_Code.gerhjby9.dll'. Type B originates from 'App_Code.exfj_hx2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
How can fix this issue?.
Thanks & regards,
Feb 18, 2019 01:47 AM|Ackerly Xu|LINK
Hi dileep Sanker,
It seems you are trying to cast one type in an assembly to one type in another assembly although they have the same namespace and class name.
You could rebuild your project to remove the old assembly ,maybe your server B is using a type from old assembly in session.
Please refer to the two links below which have similar problem.
Feb 18, 2019 06:17 AM|dileep Sanker|LINK
Am not clear what I have to do.
Thanks & Regards,
Feb 18, 2019 06:54 AM|Ackerly Xu|LINK
Have you seen the solution below?
for debugging purposes - start new browser session / clear cookies or just trigger app-pool recycle (i.e. by touching web.Config).
Just try to close your current browser and reopen it.
Or change your web.config and save it.
About the second solution .
consider moving objects to class library project and adding reference to it from web site - this way you control when types are actually re-compiled and thus will not lose identity due to dynamically generated assembly file name.
You could define ProfileCommon in a class library and make your website refer to the library.
Feb 18, 2019 07:23 AM|dileep Sanker|LINK
If I clear browser session / clear cookies
, then some time it working fine without error. But some time again the previous error came as,
System.InvalidCastException: [A]ProfileCommon cannot be cast to [B]ProfileCommon.
How we can identify the real problem and fix.
Feb 18, 2019 07:49 AM|Ackerly Xu|LINK
It is just a debug solution.As the second solution shows, try to move your ProfileCommon to a class library and add reference to it.
Feb 18, 2019 08:00 AM|dileep Sanker|LINK
I don't know why some time it is working and sometime it is not working With first solution.
I tried with second solution also, no luck. here also some time it is working and sometime it is not.
Feb 18, 2019 09:46 AM|Ackerly Xu|LINK
Could you remove .net cache, there may be duplicate files generated by .net, please remove the cache.
Please refer to
Also check the explanation below.
Feb 18, 2019 02:26 PM|dileep Sanker|LINK
I have added some key value in web config and try to load the site.
Here also after that changes, working without any issue for some time not working with same error.
I cant remove the .NET cache by Physically Since don't have permission. Deleting .net Cachae physically is not applicable for me. The same thing can we do by programmatically or any config settings changes.
Thanks & regards.
Feb 19, 2019 01:15 AM|Ackerly Xu|LINK
If you don't have permission , you could try to change your permission.
One way is to change the permission of the folder that stores cache.
Or you could change the identity of your application pool to LocalSystem , so that you could delete the folder through asp.net program.