0

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.

srajeshnkl
  • 883
  • 3
  • 16
  • 49
  • 2
    The URL is bad. Try putting the entire pathname rather that just the filename. I'm not sure if the issue is with the filename or the urls inside the schema. It kind of looks like the firewall inside your company is blocking the schema of checking the Urls for the schema. – jdweng Nov 04 '18 at 09:46
  • @jdweng thanks for looking into this issue. The same code works with vs 2010 + .net 4.0. the issue is only with vs 2017 + .net 4.6.2 – srajeshnkl Nov 04 '18 at 10:08
  • 1
    Did you fully recompile with 2017. I usually make a copy of the bin folder and then delete. This will force a recompile. The c# compiled code uses dll that are part of windows and unless the installed dll exactly match the ones that were used to compile the code the code may not work. Usually you should publish the application and then run the setup.exe that is created when you run on another machine just like commercial purchased software. If that doesn't solve issue the use a sniffer like wireshark or fiddler and compare the working with non working applications. – jdweng Nov 04 '18 at 11:23
  • @jdweng: yes it's compiled fully. From your first comment got a clue and I tried to run the application with admin rights. Now Add call succeeds. Now I'm looking for the waly to make it work with out admin rights. – srajeshnkl Nov 04 '18 at 12:27
  • 1
    Open schema and see if the are any path names. There may be a link to another PC or network drive you cannot reach. – jdweng Nov 04 '18 at 12:51

0 Answers0