Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I have an issue while removing namespace prfix "asmv2". It is throwing null reference exception.

Please see below code snippet:

C#
<pre>/// <summary>
  /// Remove lines from the manifest that contain filenames that do not
  /// exist in the addin bin folder
  /// </summary>
  /// <param name="manifest">Manifest file to edit</param>
  private static void SanitizeManifestToMatchBin(string manifest, string addInBinFolder)
  {
     // load manifest
     XDocument xDoc = XDocument.Load(manifest);
     xDoc.Root.Attribute(XNamespace.Xmlns + "asmv2").Remove();
     XNamespace ns = "urn:schemas-microsoft-com:asm.v2";

     // remove any files from dependentAssembly/codebase that do not exist in the bin folder
     xDoc.Descendants(ns + "dependentAssembly")
        .Where(x => (string)x.Attribute("dependencyType") == "install" && File.Exists(addInBinFolder + "\\" + (string)x.Attribute("codebase").Value) == false)
        .Select(x => x.Parent)
        .Remove();

     //xDoc.Descendants(ns + "file")
     //   .Where(x => File.Exists(addInBinFolder + "\\" + (string)x.Attribute("name").Value) == false)
     //   .Select(x => x)
     //   .Remove();

     //xDoc.Descendants(ns + "file").Remove();
     xDoc.Save(manifest);
  }


At above code snippet,
C#
xDoc.Root.Attribute(XNamespace.Xmlns + "asmv2").Remove(); //is throwing null reference exception.


Below is my xml manifest:

C#
<pre><asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" 
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" 
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" 
xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 
xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">


What I have tried:

In above xml manifest, I found that "asmv2" is not available and I am trying to remove this entry.I tried checking why this entry is not there but no luck.

Please help me to solve this problem.

Thank you.
Posted
Comments
Richard MacCutchan 16-Sep-20 3:39am    
You cannot remove something that does not exist.
Member 13187373 16-Sep-20 4:23am    
Why that asmv2 attribute is not there in the xml manifest file when the xml manifest file is generated. May be that depends on some package installation on a machine?
Richard MacCutchan 16-Sep-20 4:39am    
I have no idea, but the contents of a manifest depend on the structure of your application and what features it is using. You should not make assumptions about what it contains.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900