XMLSChemaSet.Add fails in Visual studio 2017

265 views Asked by At

I have the below code which works perfectly works with Visual Studio 2010,

string path = @"Path_to_XML.xml";
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);


XmlReaderSettings settings = new XmlReaderSettings
{
          ValidationType = ValidationType.Schema
};

 settings.Schemas.Add(@"REQUIRED_NAMESPACE",
                      @"REQUIREDSCHEMA.xsd");

But when used with Visual Studio 2017, it fails to add schema; ie., Fails in the line,

settings.Schemas.Add(...)

with below exception,

$exception {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"} System.ArgumentException

at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone& zone, StringHandleOnStack retUrl) at System.Security.Policy.PEFileEvidenceFactory.GenerateLocationEvidence() at System.Security.Policy.PEFileEvidenceFactory.GenerateEvidence(Type evidenceType) at System.Security.Policy.AssemblyEvidenceFactory.GenerateEvidence(Type evidenceType) at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate) at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type) at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed) at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType) at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate) at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type) at System.Security.Policy.Evidence.RawEvidenceEnumerator.MoveNext() at System.Security.Policy.Evidence.EvidenceEnumerator.MoveNext() at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName) at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath) at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord record) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Xml.XmlConfiguration.XmlReaderSection.get_ProhibitDefaultUrlResolver() at System.Xml.Schema.Parser..ctor(SchemaType schemaType, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler) at System.Xml.Schema.XmlSchemaSet.ParseSchema(String targetNamespace, XmlReader reader) at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, String schemaUri)

How to resolve this issue?

Note: The only difference I see is the System.XML.dll is referred from .Net 4.6.2 in VS 2017 and in VS 2010, it is referred from .Net 4.0.

0

There are 0 answers