I'm attempting to dynamically load some (purchased) assemblies from resource streams in a C# program during an MSI installation routine, but I'm getting "Unverifiable code failed policy check".
I read some tips online about compiling the embedded assembly with /clr:safe, but I don't have that option. Is there a way to work around this policy check?
Thanks.
The only way to load unverifiable code is from a full trust process (or maybe app domain) with verification disabled.
EDIT: I'm not making this up, one of the C# language designers said "Unverifiable code requires full trust and is generally to be avoided"
Its already too late, but it may help someone.
I've used Sqlite DLL in my project and when I deployed the code on sandbox environment, I was getting exception (see below)
[FileLoadException: Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
[FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.79.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
I added trust level within system.web in the web.config file and its working fine.
<trust level="Full|High|Medium|Low|Minimal" originUrl="url"/>
This may not be relevant any longer, but I encountered the same issue recently. If you take the stream and stick it in a temp file, you can then use Assembly.LoadFrom to load the assembly.
Related
Since today I get the following new Error message:
System.IO.FileLoadException: Could not load file or assembly 'WebDriver, Version=2.53.1.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) ---> System.IO.FileLoadException: A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
Everything worked fine until yesterday and now I lost 6 out of my 7 test VMs to this error.
I read every documentation I could find and tried to compare the non working VMs with the the non working version and could not find a difference.
Suspicious is the Version=2.53.1.0 as the current WebDriver DLL is 4.4.0. Where could the reference to this potential old DLL come from?
Is there a debug or logging option I could activate? A way to see which DLLs are loaded?
Needless to say that with only 1 out of 7 Testmachines we will not be able to meet the deadline.
Got it. It's the other way around. I must not use a new version. I must use an old 2.53 version.
The update must have slipped in because I can't remember updating them consciously.
For those who have similar problems: Extract the content of selenium-dotnet-strongnamed-2.53.1.zip into C:\Program Files (x86)\Common Files\microsoft shared\VSTT\Cross Browser Selenium Components\
Adjust destination directory if you have an unusual Windows installation.
when I upload the website on the host below error accrue I don't have any problem in localhost but when I upload it on a host this error accrues:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Reference.svcmap: Could not load file or assembly 'Microsoft.SqlServer.SqlEnum, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
Source Error:
[No relevant source lines]
Source File: /App_WebReferences/XMLForSMSServiceReference1/ Line: 1
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.SqlServer.SqlEnum, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' could not be loaded.
what should I do?
Best Regards
Neda
Possible duplicate of : C# SMO and SqlEnum references error
Short answer is the binaries you are deploying on to target server are missing referenced binaries (I am guessing the Sql server SMO library).
When you deploy a project to the destination you have to ensure the destination has the shared components (such as SQL SMO) already installed there, if not you have to include such shared binaries through your msi/deployment.
In your case there are two possible workarounds depending upon how you want to achieve it.
Create the msi and include all binaries (including the once those go in global cache - strongly signed libraries) - this is the more sensible way of handling standard deployment scenarios.
Only deploy your project binaries but ensure the referenced packages are already installed on destination.
In the web.config of webforms .net 4.5 application I set the following:
<trust legacyCasModel="true" level="Full" />
because this is a Microsoft work around to overcome an bug in the asp.net Report Viewer which causes large reports to take much longer to generate than in previous .net versions (3.5 and older). Unfortunately, enabling the legacy CasModel has caused the error below. As the error suggests I have attempted many times to apply an exception in my site's web.config such as:
<system.web>
<partialTrustVisibleAssemblies>
<add assemblyName="System.Web.Extensions" version="4.0.0" publicKey="0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9" />
</partialTrustVisibleAssemblies>
</system.web>
But the error still occurs. I also attempted to apply this setting to the .net 4 web.config and specify this assembly to have full trust but it still won't work. I've read a ton of documentation pertaining to this issue and I cannot locate any other way this issue maybe resolved (except to remove this assembly in my project or make other major changes to my web application). Any suggestions of how I can fix or address this issue would be greatly appreciated, Thanks.
Server Error in '/' Application.
Attempt by security transparent method 'Microsoft.ScriptManager.MSAjaxv45.PreApplicationStartCode.Start()' to access security critical method 'System.Web.UI.ScriptManager.get_ScriptResourceMapping()' failed.
Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MethodAccessException: Attempt by security transparent method 'Microsoft.ScriptManager.MSAjaxv45.PreApplicationStartCode.Start()' to access security critical method 'System.Web.UI.ScriptManager.get_ScriptResourceMapping()' failed.
Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.
Try removing "Microsoft.ScriptManager.MSAjax.dll" and "Microsoft.ScriptManager.WebForms.dll" from references(if not used).
#Sachin, thank you for your answer however I need those assemblies for this project so that would not resolve this issue. I resolved this issue a while ago. I think this error was occurring when attempting some authentication functions in the application. I resolved the issue by setting the report function to open in a new application pool, so that the enabling of the legacy CAS model only effects the new application pool and therefore not effecting other authentication functions in the application.
Occasionally I have problems with applications which rely on unmanaged .dll's throwing exceptions which look like:
System.IO.FileLoadException: Could not load file or assembly 'AssemblyXXXX, Version=1.0.4099.27218, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
File name: 'AssemblyXXXX, Version=1.0.4099.27218, Culture=neutral, PublicKeyToken=null' ---> System.Runtime.InteropServices.COMException (0x800736B1): This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
The main problem is, that it does not say which dll could not be loaded, or which COM object is not registered.
Are there any tools that help track down this problem?
Fuslogvw shows you details of assembly loading errors. However, I'm guess that it's a COM
problem.
Try loading each of the COM dependencies dynamically (maybe in a different program, and maybe using their progid) using Type.GetTypeFromProgID and Activator.CreateInstance, and catching each error individually.
In the past, I've seen this error when there are different (older) versions of Office installed on user's machines.
I'm using CS-Script (link: http://www.csscript.net/) to compile a script file. According to their documentation, I'm doing it right.
new AsmHelper(CSScript.Compile("test.cs"), null, true);
However at runtime, I get:
Could not load file or assembly
'file:///C:\Users...\CSScriptLibrary.dll'
or one of its dependencies. Operation
is not supported. (Exception from
HRESULT: 0x80131515)
I'm somehow suspecting .NET 4.0 or some obscure manifest, but I did add the CSScriptLibrary.dll in the .NET 4.0 directory of cs-script/Lib/Bin.
Any suggestion?
Make sure you add it as a reference in your C# project.
See here for info on how to do it: http://msdn.microsoft.com/en-us/library/7314433t(VS.80).aspx
-Edit-
If that doesn't work, try this: Link