Domanda

In the YSOD below, the stacktrace (and the source file line) contain the full path to the source file. Unfortunately, the full path to the source file name contains my user name, which is firstname.lastname.

I want to keep the YSOD, as well as the stack trace including the filename and line number (it's a demo and testing system), but the username should vanish from the sourcefile path. Seeing the file's path is also OK, but the path should be truncated at the solution root directory.

(without me having to copy-paste the solution every time to another path before publishing it...)

Is there any way to accomplish this ?

Note: Custom error pages aren't an option.

enter image description here

È stato utile?

Soluzione 2

Never mind, I found it out myself.
Thanks to Anton Gogolev's statement that the path is in the pdb file, I realized it is possible.

One can do a binary search-and-replace on the pdb file, and replace the username with something else.

I quickly tried using this:
https://codereview.stackexchange.com/questions/3226/replace-sequence-of-strings-in-binary-file
and it worked (on 50% of the pdb files). So mind the crap, that code-snippet in the link seems to be buggy.

But the concept seems to work.

I now use this code:

    public static void SizeUnsafeReplaceTextInFile(string strPath, string strTextToSearch, string strTextToReplace)
    {
        byte[] baBuffer = System.IO.File.ReadAllBytes(strPath);
        List<int> lsReplacePositions = new List<int>();

        System.Text.Encoding enc = System.Text.Encoding.UTF8;

        byte[] baSearchBytes = enc.GetBytes(strTextToSearch);
        byte[] baReplaceBytes = enc.GetBytes(strTextToReplace);

        var matches = SearchBytePattern(baSearchBytes, baBuffer, ref lsReplacePositions);

        if (matches != 0)
        {

            foreach (var iReplacePosition in lsReplacePositions)
            {

                for (int i = 0; i < baReplaceBytes.Length; ++i)
                {
                    baBuffer[iReplacePosition + i] = baReplaceBytes[i];
                } // Next i

            } // Next iReplacePosition

        } // End if (matches != 0)

        System.IO.File.WriteAllBytes(strPath, baBuffer);

        Array.Clear(baBuffer, 0, baBuffer.Length);
        Array.Clear(baSearchBytes, 0, baSearchBytes.Length);
        Array.Clear(baReplaceBytes, 0, baReplaceBytes.Length);

        baBuffer = null;
        baSearchBytes = null;
        baReplaceBytes = null;
    } // End Sub ReplaceTextInFile

Replace firstname.lastname with something that has equally many characters, for example "Poltergeist".

Now I only need to figure out how to run the binary search and replace as a post-build action.

Altri suggerimenti

Path is embedded in .pdb files, which are produced by the compiler. The only way to change this is to build your project in some other location, preferably somewhere near the build server.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top