Code Access Security problem - what's the issue here? - c#

Background
I have a post-build event which I use to generate some batch files which contain the current version number of our application. The event calls a batch file, which calls a managed app which loads the assembly and uses reflection to find its version information.
Problem
When the post-build event runs locally, every is fine. When it's run under our automated build process, I see the following error in the logs. I know nothing about Code Access Security, and was hoping someone could point out the problem quickly.
call GenerateBatchFiles.bat Q:\MyApp\MyCompany.Services.Hosts.MyApp.exe
Unhandled Exception: System.Security.SecurityException: Request failed.
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at Version.Program.Main(String[] args)
The action that failed was:
LinkDemand
The type of the first permission that failed was:
System.Security.PermissionSet
The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="USERNAME"/>
<IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Unrestricted="true"/>
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="Q:\MyApp\"
PathDiscovery="Q:\MyApp\"/>
<IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Allowed="AssemblyIsolationByUser"
UserQuota="9223372036854775807"
Expiry="9223372036854775807"
Permanent="True"/>
<IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="ReflectionEmit"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Assertion, Execution, BindingRedirects"/>
<IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Unrestricted="true"/>
<IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Url="file:///Q:/MyApp/Version.exe"/>
<IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Zone="Intranet"/>
<IPermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Unrestricted="true"/>
<IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
Level="DefaultPrinting"/>
</PermissionSet>
The assembly or AppDomain that failed was:
Version, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Zone of the assembly that failed was:
Intranet
The Url of the assembly that failed was:
file:///Q:/MyApp/Version.exe

Which version of the framework are you using? Older versions don't trust network shares much - so you might need to use "caspol" to enable trust (or move the file locally before running it). More recently, the framework does trust mappped shares (such as Q:\), but doesn't trust UNC shares (\\someserver\whatever) without a "caspol" tweak.
The simplest option, though, is to run the exe from a local drive rather than over the network.

Related

Azure Storage Account - error 403 forbidden

I have an Azure Function that should process files in a storage account container. The Azure Function should be triggered every day. But once or twice a week I see that some Files in the container are not processed: (At the beginning 401 files from 600 are not processed, because of error 403)
As I read here in Stackoverflow. It is because of SAS token time skew. Is it possible without a big changing in my code, I solve this problem?
my code:
CloudStorageAccount sa;
CloudStorageAccount.TryParse("MyConnString", out sa);
_blobClient = sa.CreateCloudBlobClient();
ICloudBlob sourceBlob = _blobClient.GetBlobReferenceFromServer(new Uri(BlobUrl));
Update
Message Exception while executing function:
process_files_by_http_trigger_activity The remote server returned an
error: (403) Forbidden. The remote server returned an error: (403)
Forbidden.
Call Stack:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__16.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__13.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) Inner exception
Microsoft.WindowsAzure.Storage.StorageException handled at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw: at
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync
(Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35Microsoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.csMicrosoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
604) at
Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer
(Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35Microsoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobClient.csMicrosoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
563) at
Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer
(Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35Microsoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobClient.csMicrosoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
546) at
bip.dev.afu.inbound.we.process_xz_files_by_http_trigger.XzFileMove
(bip.dev.afu.inbound.we, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null) at
bip.dev.afu.inbound.we.process_xz_files_by_http_trigger+d__10.MoveNext
(bip.dev.afu.inbound.we, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker2+<InvokeAsync>d__2.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker2+d__9.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__24.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__23.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__22.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b7xxxx934e089) at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7xxxx934e089)
at
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+d__16.MoveNext
(Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35) Inner exception
System.Net.WebException handled at
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync:
at System.Net.HttpWebRequest.GetResponse (System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b7xxxx934e089) at
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync
(Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral,
PublicKeyToken=31bfxxxx64e35Microsoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35:
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.csMicrosoft.WindowsAzure.Storage,
Version=7.2.1.0, Culture=neutral, PublicKeyToken=3xxxxx6ad364e35:
677)
Start with the basics, An Azure Storage connection string uses following format. Please make sure you have provided a right account name and key pair for the connection string. If you set account n1 and account key for account n2, it will cause the exception.
DefaultEndpointsProtocol=https;AccountName=[accountName];AccountKey=[accountKey];EndpointSuffix=core.windows.net
I would suggest you to print you connection string and see if it is the same all the time as you mentioned in the App.setting.
Trace.Write(ConnectionString);
Please ensure that the current date time of your system/app instance is correct.
The storage services ensure that a request is no older than 15 minutes by the time it reaches the service. This guards against certain security attacks, including replay attacks. When this check fails, the server returns response code 403 (Forbidden).
Hope it helps.Feel free to tag me in your conversation for any additional help.

Correct use of app and local settings with Azure Function Bindings?

I am developing some Azure Functions in Visual Studio 2017 that use EventHub, ServiceBus, SignalR, CosmosDB and other bindings. Many of the bindings have a Connection or ConnectionStringSetting argument that is supposed to be set to the name of the setting that holds the connection string.
For example:
[EventHubTrigger(eventHubName: "the-hub-name", Connection = "MySettingName")] TheRequestEventType request
I have the MySettingName value in the Values section of my local.settings.json. This all works fine for running and debugging locally.
When I added MySettingName to the App Settings on the Azure Functions App and deployed the App things do not work. When the app starts I get exceptions stating that the connection string is null: Error indexing method 'MyEventHandler.Run' Value cannot be null. Parameter name: connectionString (full call stack provided below).
What is the correct way to use the Connection or ConnectionStringSetting arguments?
Is there some naming convention that must be used like APPSETTING_MySettingName?
I've been searching for documentation on this and using App Settings with Function Apps in general but not found anything that address this, sorry in advance if I've missed something obvious.
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException:
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 175)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexTypeAsync>d__13.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 103)
Inner exception System.ArgumentNullException handled at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext:
at Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse (Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Azure.EventHubs.Processor.EventProcessorHost..ctor (Microsoft.Azure.EventHubs.Processor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at Microsoft.Azure.WebJobs.EventHubs.EventHubOptions.GetEventProcessorHost (Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.EventHubs\Config\EventHubOptions.csMicrosoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 247)
at Microsoft.Azure.WebJobs.EventHubs.EventHubTriggerAttributeBindingProvider.TryCreateAsync (Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.EventHubs\Triggers\EventHubTriggerAttributeBindingProvider.csMicrosoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 68)
at Microsoft.Azure.WebJobs.Host.Triggers.CompositeTriggerBindingProvider+<TryCreateAsync>d__2.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\CompositeTriggerBindingProvider.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 22)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsyncCore>d__18.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 190)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 167)
You did it right that adding those Connection String settings(e.g. MySettingName and corresponding value)to the App Settings on the Azure Functions. There's no naming convention either.
The null value exception probably results from missing AzureWebJobsStorage in App Settings, this storage account connection string is required for all triggers except Http trigger. The storage account must be a general-purpose one that supports blobs, queues, and tables.
The fact that it works when debugging locally means, your local.settings.json is correct and has "MySettingName" configured correctly.
As far as I can understand, it doesn't work when you deploy to Azure. When running in Azure, it doesn't look at local.seetings.json. Instead Azure looks at "Application Settings" of your function app.
So edit application settings and add "MySettingName" there. That should solve your issue.

Assembly could not be converted to type library - Error:Type library exporter cannot load type

I am trying to build one of the older components which uses .NET Framework 2.0
If I build same component with .Net Framework 4.0 it builds successfully but;
when .Net framework 2.0 is used, build fails with error "Assembly could not be converted to type library."
Following is complete error report for this error:
Error 14 The assembly "X:\MyAssembly.dll" could not be converted to a type library. Type library exporter encountered an error while processing 'Namespace.ComponentName, ProjectName'. Error: Type library exporter cannot load type 'Namespace.ComponentName' (error: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
The action that failed was:
InheritanceDemand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="UnmanagedCode"/>
The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="UnmanagedCode"/>
</PermissionSet>
The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Perm
I want to build this assembly on .Net framework 2.0
What should I do to get rid of this error. Please point me in the right direction...
As pointed out by user Hans Passant, indeed X: drive was the problem.
I was not able to get it working using CASPOL command by giving it "full trust".
But, I was able to build when I mapped X: drive using SUBST command.
So, Mapping X: drive by using SUBST command fixed my issue.
subst X: D:\XDriveFolderToBeMapped

Custom delivery UI extension generates "Invalid Class Name" error

I've done nothing more than compile the sample SSRS delivery extension and deploy it to the server as per instructions. When I make a call to the ReportService2010 ListExtensions web service method, the extension shows up in the list of results. However, when I go to create a subscription in the Report Manager, as soon as I choose the Printer Delivery Sample from the drop-down list of available delivery extensions, I get this error:
Invalid Class Name
I'm running SSRS 2012 SP2 (11.0.5569.0) on Windows Server 2012 R2.
EDIT: I found this in the logs:
It turns out that the ReportManager (the ASP.NET UI) does log to the C:\Program Files\Microsoft SQL Server\MSRSxx.MSSQLSERVER\Reporting Services\LogFiles directory. I initially saw only subscription- (i.e. service-)related events in those files and assumed that if the ReportManager did log, those files must be elsewhere.
extensionfactory!ReportManager_0-3!53c!06/02/2015-16:27:40:: e ERROR: Exception caught instantiating Printer Delivery Sample report server extension:
System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Reflection.Assembly.GetType(String name, Boolean throwOnError)
at Microsoft.ReportingServices.Diagnostics.ExtensionClassFactory.<>c__DisplayClass9.<GetExtensionLocalizedName>b__6()
at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.<>c__DisplayClass1.<Run>b__0(Object state)
at System.Security.SecurityContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.Run(ContextBody callback)
at Microsoft.ReportingServices.Diagnostics.ExtensionClassFactory.GetExtensionLocalizedName(Extension extConfig, Boolean removeFailuresAndContinue)
The action that failed was:
InheritanceDemand
The type of the first permission that failed was:
System.Web.AspNetHostingPermission
The first permission that failed was:
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Minimal"/>
The demand was for:
<PermissionSet class="System.Security.PermissionSet" version="1">
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Minimal"/>
</PermissionSet>
The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet" version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execution"/>
<IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PublicKeyBlob="00240000048000009400000006020000002400005253413100040000010001009D92F3DD932D20261ADD96F81554DD22E89D6C820CE81177D791891A9415FE8499B0A22270329D737DD29FCF15784BCE44B876E2099FA06B113712581C764E7B033E3F487EA8774CB78CB79FA5951A501F4FA61496F0E07AB2A48020A99435C0F2DE60282540E72CCCB63F05ECEFB90BD542E30EE34AA8005C51F2EC0BF606C0" Name="Microsoft.Samples.ReportingServices.PrinterDeliverySample" AssemblyVersion="1.0.5627.17054"/>
<IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Url="file:///C:/Program Files/Microsoft SQL Server/MSRS11.MSSQLSERVER/Reporting Services/ReportManager/bin/Microsoft.Samples.ReportingServices.PrinterDeliverySample.DLL"/>
<IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Zone="MyComputer"/>
</PermissionSet>
The assembly or AppDomain that failed was:
Microsoft.Samples.ReportingServices.PrinterDeliverySample, Version=1.0.5627.17054, Culture=neutral, PublicKeyToken=f0209f2bcebc8576
The Zone of the assembly that failed was:
MyComputer
The Url of the assembly that failed was:
file:///C:/Program Files/Microsoft SQL Server/MSRS11.MSSQLSERVER/Reporting Services/ReportManager/bin/Microsoft.Samples.ReportingServices.PrinterDeliverySample.DLL
Yes, I feel a bit foolish. Okay - now what do I do with this information? Time to brush up on Code Access Security again...
Have a look at this:
http://blogs.msdn.com/b/friis/archive/2010/06/09/system-security-securityexception-request-for-the-permission-of-type-system-web-aspnethostingpermission-failed.aspx
Try switching the Application Pool Identity to Network Service. Also, check your DLL to see if it needs to be unblocked, which is also mentioned in that article.
Can you please confirm your failed assembly available/registered at C:\windows\assembly of reportserver machine. if its not registered then try to install that in GAC "Install an Assembly into the Global Assembly Cache"
Global Assembly Cache

Issue with Code Access Security Policy - deploying a third party dll to bin [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Okay, i think most of you guys out there use wspbuilder to build the wsp solutions and to deploy it. So here is my problem.
I'm working on a SharePoint solution which makes use of a third party dll (Telerik for Asp.Net Ajax - Telerik.Web.UI.dll) for rich experience. Since Telerik dll is a common assembly i have to deploy it to the bin folder of the webapplication instead of GAC. So here comes the problem.
WSPBuilder automatically deploys the dll to gac if the dll presents in the GAC folder. To deploy the telerik dll in bin i created the folder 80\bin and copied the dll there. I tried to build the wsp again and then went through the manifest.xml created. Great. The deployment target for the dll changed to WebApplication and wspbuilder was smart to create the cas policy itself.
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class="NamedPermissionSet" version="1" Description="WSPBuilder generated permissionSet" Name="Telerik.Web.UI4a48967c-0673-4c67-a176-ca7c72c30c4d">
<IPermission class="PrintingPermission" version="1" Level="DefaultPrinting" />
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" />
<IPermission class="SharePointPermission" version="1" ObjectModel="True" />
<IPermission class="EnvironmentPermission" version="1" Read="TEMP;TMP;USERNAME;OS;COMPUTERNAME" />
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Minimal" />
<IPermission class="WebPartPermission" version="1" Connections="True" />
<IPermission class="FileIOPermission" version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
<IPermission class="WebPermission" version="1">
<ConnectAccess>
<URI uri="$OriginHost$" />
</ConnectAccess>
</IPermission>
<IPermission class="IsolatedStorageFilePermission" version="1" Allowed="AssemblyIsolationByUser" UserQuota="9223372036854775807" />
<IPermission class="DnsPermission" version="1" Unrestricted="true" />
<IPermission class="SmtpPermission" version="1" Access="Connect" />
<IPermission class="SqlClientPermission" version="1" Unrestricted="true" />
</PermissionSet>
<Assemblies>
<Assembly Name="Telerik.Web.UI" Version="2010.2.826.35" PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010069F31F753C891D9F7F9D1CD0B579F61977769A5A48E01247CC2481C8765613854C8DCB5101DD092D5075A7339B4E34D0C9BD417F54972C7554AE480D6B1BB17BE8C1527554644BBD352D9498B174EAFF1090A30E1F7C2C3073669CB3EFC7D9640E82049F5FDA08CA58072C14169091A0BC7092EB6DE9C2A249A3C80F7704E5CF" />
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
But Wspbuilder was not smart enough to put the four part name of SharePointPermission IPermission class. But i learnt that CAS actually requires the four part name. So i decided to make use of the -CustomCAS command line option of wspbuilder.exe to pass my custom cas policy file.
Here is my custom policy file -
<IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execute" />
<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" UnsafeSaveOnGet="True" Unrestricted="True" />
<IPermission class="System.Security.Permissions.EnivronmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName" />
So after building the wsp the cas section of the manifest.xml read this -
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class="NamedPermissionSet" version="1" Description="WSPBuilder generated permissionSet" Name="Telerik.Web.UIa2cbae96-9c52-459e-80f6-3391af7775ae">
<IPermission class="PrintingPermission" version="1" Level="DefaultPrinting" />
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" />
<IPermission class="SharePointPermission" version="1" ObjectModel="True" />
<IPermission class="EnvironmentPermission" version="1" Read="TEMP;TMP;USERNAME;OS;COMPUTERNAME" />
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Minimal" />
<IPermission class="WebPartPermission" version="1" Connections="True" />
<IPermission class="FileIOPermission" version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
<IPermission class="WebPermission" version="1">
<ConnectAccess>
<URI uri="$OriginHost$" />
</ConnectAccess>
</IPermission>
<IPermission class="IsolatedStorageFilePermission" version="1" Allowed="AssemblyIsolationByUser" UserQuota="9223372036854775807" />
<IPermission class="DnsPermission" version="1" Unrestricted="true" />
<IPermission class="SmtpPermission" version="1" Access="Connect" />
<IPermission class="SqlClientPermission" version="1" Unrestricted="true" />
<IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execute" />
<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" UnsafeSaveOnGet="True" Unrestricted="True" />
<IPermission class="System.Security.Permissions.EnivronmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName" />
</PermissionSet>
<Assemblies>
<Assembly Name="Telerik.Web.UI" Version="2010.2.826.35" PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010069F31F753C891D9F7F9D1CD0B579F61977769A5A48E01247CC2481C8765613854C8DCB5101DD092D5075A7339B4E34D0C9BD417F54972C7554AE480D6B1BB17BE8C1527554644BBD352D9498B174EAFF1090A30E1F7C2C3073669CB3EFC7D9640E82049F5FDA08CA58072C14169091A0BC7092EB6DE9C2A249A3C80F7704E5CF" />
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
After i deployed the wsp i verified
* the dlls going to bin
* the trust level changed to custom trust level
* custom policy file being added to config folder
But when i run the page i get the following error -
screen shot -
Error -
Execution Permission Denied
Stack Trace -
Tell me if you want the stack trace. It is kind of annoyingly big.
I've checked my entire application for any assembly references of the dll. But i was not able to find one. Any ideas?
I think you just have a typo in your CAS policy:
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execute" />
It should be Flags="Execution" not "Execute"

Categories