loadFromRemoteSources

Hello, I would like to use the following code however I got the error message that;

Message: 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.

Does anyone have idea how to fix it?

I have checked the config files in the IronPython folder but it seems everything right;

  <runtime>
    <!-- Enable loading assemblies from network shares or downloaded from the internet. -->
    <loadFromRemoteSources enabled="true"/>
  </runtime>

script sample (for csv reading for IronPython)

# COPYRIGHT NOTICE: 
# This demo script uses the CSV reader by Sebastien Lorion 
# You can find his library including source code  
#     at http://www.codeproject.com/cs/database/CsvReader.asp. 
# Copyright for the CSV library by Sebastien Lorion, 2005. 
# The library is licensed under MIT Open Source License. 

# Necessary imports to enable access to CSV reading component 
from System.Reflection import Assembly
assemblyPath = r"C:\CSVFramework\LumenWorks.Framework.IO.dll"
assembly = Assembly.LoadFile(assemblyPath)
clr.AddReference(assembly)
from System.IO import StreamReader
from LumenWorks.Framework.IO.Csv import CsvReader

# Read projects from time cockpit database
projects = Context.Select("From P In Project Select New With { " 
    ".CustomerCode = P.Customer.Code, .ProjectCode = P.Code, " 
    ".Project = P }")

# Read current user from database
user = Context.SelectSingle("From U In UserDetail " 
    "Where U.UserDetailUuid = Environment.CurrentUser.UserDetailUuid Select U")

# Create reader to read content of CSV file
fileReader = StreamReader(r"wall.csv")
try:
    # Create component for reading CSV file 
    # Second parameter indicates whether the file has headers
    csvReader = CsvReader(fileReader, True)
    try:
        csvReader.SkipEmptyLines = True

        # Get indexes of source columns based on header. 
        # You can remove these lines if your CSV file has a static structure.
        headers = csvReader.GetFieldHeaders()
        beginTimeIndex = Array.IndexOf(headers, "BeginTime")
        endTimeIndex = Array.IndexOf(headers, "EndTime")
        customerCodeIndex = Array.IndexOf(headers, "CustomerCode")
        projectCodeIndex = Array.IndexOf(headers, "ProjectCode")
        descriptionIndex = Array.IndexOf(headers, "Description")
        if (beginTimeIndex < 0 or endTimeIndex < 0 or customerCodeIndex < 0 
            or projectCodeIndex < 0 or descriptionIndex < 0):
            raise Exception("Missing column(s) in CSV file.")

        while csvReader.ReadNextRecord():
            beginTime = DateTime.TryParse(csvReader[beginTimeIndex])
            if not beginTime[0]:
                raise Exception("Could not parse BeginTime in record {0}".format(
                    csvReader.CurrentRecordIndex))
            endTime = DateTime.TryParse(csvReader[endTimeIndex])
            if not beginTime[0]:
                raise Exception("Could not parse EndTime in record {0}".format(
                    csvReader.CurrentRecordIndex))
            project = [x for x in projects if x.CustomerCode == csvReader[customerCodeIndex]
                and x.ProjectCode == csvReader[projectCodeIndex]]
            if len(project) == 0:
                raise Exception("Error looking up project {0}.{1} (record {2})".format(
                    csvReader[customerCodeIndex],
                    csvReader[projectCodeIndex],
                    csvReader.CurrentRecordIndex))

            timesheet = Context.CreateTimesheet({ "BeginTime": beginTime[1],
                "EndTime": endTime[1], "Project": project[0].Project,
                "Description": csvReader[descriptionIndex], "UserDetail": user })
            Context.SaveObject(timesheet)
    finally:
        csvReader.Close()
finally:
    fileReader.Close()

print "Done!"

If you downloaded that DLL from the internet, you probably have to right click on the DLL and “unblock” the file on the property page.

1 Like

Thanks stevebear, it works!