loadFromRemoteSources error using Assembly.LoadFrom

Jon picture Jon · Nov 25, 2011 · Viewed 14.7k times · Source

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

Answer

Jon picture Jon · Nov 25, 2011

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