Assembly.LoadFrom() permissioning in .NET 4.0 - c#

I am having trouble with security while migrating an application from .NET 3.5 to 4.0.
I have an application that starts successfully from a network share I've mapped to z: - Z:\MyApp\App.exe.
This application makes use of add-ins, and is sometimes asked to load assemblies from a seperate location on the Intranet - y:\MyLib\Lib.dll
In .NET 4.0, I get a System.Security.Security exception then this happens:
System.IO.FileLoadException: Could not load file or assembly 'XXXX' or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A) ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
However, if I launch my application locally from C:\MyApp\App.exe, it is able to successfully load with Assembly.LoadFrom() the addin at y:\MyLib\Lib.dll.
What do I need to do to 'bless' the y:\MyLib location so that apps running from network shares are allowed to execute code from there?
Thanks,
Dave

I had a similar problem, I was able to solve it as is described in my question
Structuremap does not load registries when started from Network drive.
I hope this solves your problem also.

Related

How to fix exception "Request for the permission of type System.Security.Permissions.EnvironmentPermission ... failed"

I am having an issue with a .NET application that dynamically loads dlls (plugins) at runtime. When the application is located on a network drive and is executed from a Windows 10 computer then it would throw the following System.Security.SecurityException:
Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
Via debugging I figured out that the exception is thrown when calling the function Assembly.CreateInstance(string typeName, bool ignoreCase)
The only solution I found for this issue is this: https://stackoverflow.com/a/27512051/9284286
However, it would require a lot of time to create a new version of the application and roll it out so I'd prefer a solution that does not require any changes in the application. Is there any way to grant additional permissions to the user who is having this problem or to the computer/system so that the exception no longer occurs?

Could not load file or assembly System.ServiceModel, or one of its dependencies. Not enough storage is available to process this command

The full message is
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, or
one of its dependencies. Not enough storage is available to process
this command. (Exception from HRESULT: 0x80070008)
Was running the program on .net framework 4.5 and on a windows 2008.
I found several similar posts but none point to the problem in my case.
By removing the call to the WCF i found out that was a memory problem.
The process consumed more memory than the process memory limit for a windows 32b system.
The message part Not enough storage was the difference i found from errors on other posts.

SecurityException occured, Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib'

On this line I get the following exception:
using (Stream reader = File.Open(m_inputFile, FileMode.Open))
Exception:
The message is: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
This happens in an Excel addin running in ExcelDNA, however this fails as soon as the XLL for Excel is put on a network drive.
How can I allow full permissions to read from local drives as I am on a secure network ?
This is probably due to the default security settings under .NET 2.0, which grant restricted permissions to code running over a network.
The first step is the ensure that you are running a recent version of Excel-DNA - there were some changes related to the security of the AppDomain setup a few years ago that might be relevant.
Another fix you can try is to retarget your add-in to .NET 4.0. You probably don't even have to recompile, just change your .dna file to start with:
<DnaLibrary RuntimeVersion="v4.0" Name="..." >
If you want to stick with the .NET 2.0 runtime, you can change the permissions by using the caspol utility. There are some detailed instructions in this post on the Google group: https://groups.google.com/d/msg/exceldna/Csls-_bjDp0/G3HlxFkDefQJ

Unable to run Websphere MQ application once deployed

Good day. I have developed an application which works successfully on my local machine but I have run into a problem when moving out to production.
The error is as follows:
System.IO.FileNotFoundException: Could not load file or assembly 'IBM.XMS.Admin, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d2666ab12fca862b' or one of its dependencies. The system cannot find the file specified.
File name: 'IBM.XMS.Admin, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d2666ab12fca862b'
I understand where this file is - C:\Prog... - and my .Net application is simply referencing IBM.XMS.dll which works. It's when I deploy and run I get the error above.
I used the following installation instructions and restarted the system too:
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzav.doc/un10290_.htm
Your application is built with XMS v2.5. Do you have XMS v2.5 (shipped with MQ v7.5 client) installed on the other machine?
check out Microsoft's fusion log viewer and see how you get on.
In my experience when I see this message the keywords are or one of its dependencies. The fusion log may help you find out which one.

Security exception when launching c# app from network location

i have a very small utilty app written in c# that works fine on my local machine but if i put it on a network drive and try to run it from there i get the following securityException..
Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Anyone know why and how i can fix it?
Thanks!
This is default behaviour for earlier .NET versions. It was 'fixed' in 3.5 SP1. Here is a link.
If you need to use an earlier version, the only solution is to adjust the trustlevel of the assembly (on each PC that uses it). Usually no fun.

Categories