8

I have the below code in a .Net 4 Winforms app which loads an assembly. All files are on a C:. There are numerous DLL's which work fine but two error with the following:

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

This only seems to be a problem on some PCs

Here is the code:

strDLLs = Directory.GetFileSystemEntries(strPath, "*.dll")
For intIndex = 0 To strDLLs.Length - 1
    Try
        objDLL = [Assembly].LoadFrom(strDLLs(intIndex))
        ExamineAssembly(objDLL, strInterface, Plugins)

    Catch e As Exception
        ' MsgBox("Error whilst loading Library: " & strDLLs(intIndex) & ". Reported Error was:" & vbCrLf & e.ToString)
    End Try
Next
Jon
  • 38,814
  • 81
  • 233
  • 382
  • Check this answer, may resolve your problem elegantly [http://stackoverflow.com/a/33755170/1127429](http://stackoverflow.com/a/33755170/1127429) – GMG Nov 17 '15 at 10:58
  • System.ApplicationException: STATUS_INTERNAL_ERROR: Unknown error in injected C++ completion routine. – CS QGB Mar 26 '21 at 06:50

3 Answers3

22

Well turns out the issue is because the file was possibly downloaded from the internet.

To fix Right Click -> Properties -> Unblock

enter image description here

Jon
  • 38,814
  • 81
  • 233
  • 382
2

This is how I managed to get it to work, without resorting to any clicking on client side:

var appDomain = AppDomain.CreateDomain(assemblyName);
var assembly = appDomain.Load(File.ReadAllBytes(assemblyName));

Keep in mind if you CreateDomain with Evidence parameter, you will get the 'This method uses CAS policy, which has been obsoleted by the .NET Framework.' message.

Alternatively, you can set up a proper sandbox:

http://msdn.microsoft.com/en-us/library/bb763046.aspx http://blogs.msdn.com/b/shawnfa/archive/2005/08/08/449050.aspx

Vedran
  • 10,369
  • 5
  • 50
  • 57
1

Piggybacking on Jon, I had this problem but with lots of assemblies in many different folders. I downloaded Streams from Sysinternals to unblock the files en masse. I found a good discussion on Super User about this topic.

Streams from Sysinternals Super User discussion

Community
  • 1
  • 1
Ryan Rodemoyer
  • 5,548
  • 12
  • 44
  • 54