I use xsltc.exe in developer console (ms visual studio). I try to generate a DLL that could be used in a .NET project.
xsltc /settings:dtd /settings:document /settings:script /c:Bk24.Specs specs.xsl /out:Bk24Specs.dll
I have successfully generated many of such DLLs before, but now I have a big problem. The current XSL contains a reference to an XML
<xsl:variable name="spcodes" select="document('specialCodes.xml')/list/data" />
I successfully generated the DLL for this template. I added a reference to this DLL in the .NET project. But then, the application throws an exception
File not found (c:\projects\bk24\specialCodes.xml)
in the real production environment. Of course, on the client's workstation there is no such directory C:\projects\bk24\. It's my directory on my dev machine, but when I ran xsltc.exe, I put specialCodes.xml into the same directory where the XSL is placed. I hoped that xsltc.exe would look at the directory, found that XSLs and XMLs are in the same directory, so, the generator will embed the XMLs into this DLL, but, it seems, it's not...
How can I resolve this issue?
If it is only a read only file, then open the file in a text editor and copy it. Then embed it as a string in any cs class and read with XElement.Parse(that_string)
Related
I need to maintain an xslt code that has 10s of thousands of lines.
It was developed a long time ago and it is integrated to a visual studio console application by running xsltc as a pre build event that creates a dll and that dll is finally referenced by the visual studio project.
In order to sell the final executable, I need to obfuscate the whole solution.
The tool I have been using to obfuscate works correctly for all executables and dlls files created by visual studio, but if I obfuscate my xslt dll, then my code throws a runtime error saying that it cannot find my xslt dll.
I would like to know, if you have already worked on projects using xslt dlls, how did you manage to maintain a secure version of these dlls?
I have deleted the pre-build event that ran xsltc and used the input stylesheet as an embedded resource that is not copied to the output directory.
As the stylesheet is not copied to the output directory anymore, I changed the loading code a bit:
XsltSettings settings = new XsltSettings(true, true);
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("namespace.stylesheetname.xslt");
XmlReader embeddedReader = XmlReader.Create(stream);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(embeddedReader, settings, new XmlUrlResolver());
Now I have a single executable file that I could finally obfuscate.
If you intend to use the code above, double check that you are closing the files you have opened.
Using Visual Studio 2012, I am debugging a program to find out why loading a resource file using System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream isn't working. The file is being copied to the project's bin folder correctly - but invoking System.Reflection.Assembly.GetExecutingAssembly().Location is reporting that the program is not running from there - it is running from C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\c37f9465\2be54367\assembly\dl3\c92e18ea\e852a1ef_ce6ad001.
The program is a web service, and the error occurs in a DLL called ConnectSystem.DLL (another project in the same solution), and it is this file that resides in the Microsoft.NET folder.
If this is because of Dynamic ASP.NET Compilation, which looks like the best explanation, can anyone think of a way I can incorporate my configuration file please?
The resources you are trying to load shouldn't be next to the assembly, it should be compiled into it. GetManifestResourceStream only reads resources from the assemblies themselves.
You can try to set the build action of the resource to Embedded Resource, and the file should end up in your assembly. The name may vary, usually it has the namespace as prefix. You could use Reflector to see what the actual name is.
I'm trying to use Log4net for my c# application. But when my application runs it generates log4net.xml file. As I read , It includes some information related to use in .NET documentation . But I no need this file or documentation.
How to disable log4net.xml file generation.
Your application is NOT generating this file. This file is part of the Log4Net project alongside with the assembly (log4net.dll) and the public debugging symbols (log4net.pdb). Those file are simply copied to your application's output directory. If you don't want to have them (even though it is strongly recommended to keep them), you could remove them from the source.
If on the other hand you downloaded the source code of Log4Net and compiled it yourself, then you could disable XML documentation generation in the properties of the project. In this case no log4net.xml file will be emitted.
If you are using log4net project from NuGet, remove log4net.xml file from the packages folder that was created by the NuGet(that file is under the /lib/<.net framework version>) and it will not get copied to your output.
Open command prompt as administrator
cd C:\WINDOWS\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304
Rename log4net.dll 64bit to log4net64.dll
Copy log4net.dll 32bit to folder
C:\WINDOWS\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304
Trying to integrate a dll which seems to require an xml file in a .net 4.0 C# PowerPoint Add-In this error occurs whenever calling a method from the dll:
Error: Could not find file 'C:\Users\user1\AppData\Local\assembly\dl3\6ZEM2ZRW.ODN\V57AVN2Y.7LO\c7a2a88f\00b83183_9e96c501\ASCII.xml'.
The xml file in questions is included in the project as "Content" with "Copy to output directory = always".
To me it looks like Visual Studio loads the dll into a kind of "local assembly directory" instead of using it directly from the output?
I have the source of the original dll library and a sample c# project implementing it.
In the dll it seems to be referenced like this:
public const string DefaultAsciiDataFile = #".\ASCII.xml";
In the sample project I could not find reference (using search in files), I'm not sure how the files get even loaded.
How can I get the dll to find the xml?
Update: Just putting the xml file into this temp file helps for now. Found the idea in this question.
Maybe it's related to my project being an add-in?
(Ideally without modifying / rebuilding the dll)
I wrote a form application in c# using Visual Studio 2008, third party dlls, an xml file and images. The images have been added to the project as resources.
A System.IO.FileNotFoundException is thrown when I attempt to run the published version of the executable on another machine.
If I copy the .exe file to the desktop on the pc, and also copy the dlls and the xml file to the desktop, double clicking on the exe works fine.
In my project, I have the copyLocal set to true for the required dll references. The xml is added to the project and set to copy if newer to output directory. I also checked the publish application files and everything is there.
The line I use to load the xml file is this
config = new XmlDocument();
config.Load("fileName.xml");
I'm assuming the FileNotFound exception is being thrown when you try to load the XML file, right?
Simply looking for "filename.xml" doesn't seem like a fantastic idea to me, especially if this is a key configuration file for your application.
I typically try to move these things into my App.config file then load them either using a fully qualified path or a short path. For example:
App.config
<add key="ExternalConfig" value="D:\\config.xml"/>
.cs file
config = new XmlDocument();
config.Load(ConfigurationManager.AppSettings["ExternalConfig"]);
You could also use a relative path, but keep in mind that you're always relative to the current working directory.
Alternatively, based on the type of data in your configuration, you could try to store this information to you App.config file and do away with a config.xml altogether.