I have a C # 4.0 Winform application that I just upgraded from 3.5 to 4.0. The C # 4.0 Winforms application refers to a C # 3.5 DLL, which will load a series of DLLs from network paths based on user selections and then create / invoke DLLs using System.Reflection. Everything worked perfectly when the application was configured to use 3.5 as the target structure. I got this error after updating:
An attempt was made to download the assembly from a network location, which would make the assembly isolated in previous versions of the .NET Framework. This release of the .NET Framework does not include a default CAS policy, so this download can be dangerous. If this load is not intended for the build sandbox, enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more details .
This happens when I try to load the assembly from the network path:
var assembly = Assembly.LoadFile(path);
After doing some research, I found that CAS was "partly" fixed in version 4.0. I was asked to put the following entries in my app.config:
<runtime>
<loadFromRemoteSources enabled="true"/>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
Now I get an exception:
. System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean & canBeCached, RuntimeMethodHandleInternal & ctor, Boolean & bNeedSecurityCheck) System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) System.Activator.CreateInstance( , Boolean nonPublic) System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object [] args, CultureInfo , Object [] activationAttributes) System.Activator.CreateInstance( , BindingFlags bindingAttr, , Object [] args, CultureInfo , Object [] activationAttributes) System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, , Object [] args, CultureInfo , Object [] activationAttributes) System.Reflection.Assembly.CreateInstance(String typeName) Architecture.Data.Transformations.AssemblyHelperBase.CreateInstanceExplicit [T] ( , String typeName) Architecture.Data.Transformations.MappingTransform.ProcessMap(String map, String path, IXPathNavigable doc) Architecture.Data.Transformations.MappingTransform.Execute(String map, String path, XmlDocument transformXml) Architecture.Data.Transformations.MappingTransform.Execute(XmlDocument transformXml, Int32 historyID) Architecture.Data.Transformations.TransformationsDataService.TransformXmlMap(XmlDocument transformXml, Int32 historyID) Architecture.Data.Transformations.TransformationsDataService.CreatePCSXml(HistoryRecord historyRecord) Architecture.Data.Transformations.TransformationsDataService.ReShred(Int32 historyID)
: .
, , Activator .
protected T CreateInstanceExplicit<T>(Assembly assembly, String typeName)
{
return (T)assembly.CreateInstance(typeName);
}
Windows # 4.0 Winforms ( .snk).
" ".
app.config , . , , , winforms 4.0 3.5. - ?