I have a Visual Studio program that connects to a web service and a VMware environment. Part of the process is to get connected and understand the XML that comes back (i.e. translate it in to custom objects) which involves compiling a proxy file (XML serializer assembly dll file).
I have tried to use this file in my Monotouch program, but for some reason, Monotouch doesn't seemingly want to know about the XML serializer assembly. It ignores it and so I receive XML nodes back, rather than the XML being mapped back to the correct custom object via the XML serializer assembly.
How can I get Monotouch to recognize the file and use it?
Neither Mono or any Mono-powered products (like MonoTouch or MonoDroid) support XmlSerializerAssembly.
Related
I’m trying to create add-in for outlook and have issue with deserialization and antivirus program.
I’ve noticed that when my add-in tried to deserialize any data, .NET framework created temporary dll in “C:\Users\{UserName}\AppData\Local\Temp\" folder.
This dll existed very short time, but from time to time antivirus locked it and add-in thrown error message that file is used by another process.
I’m tried to get rid of temporary dll and found recommendations to use sgen tool for creation of XmlSerializers.dll.
I generated MyAssembly. XmlSerializers.dll with strong name and placed it to the folder with add-in (C:\Program Files (x86)\MyAddin). But it doesn’t help.
Then I tried to place MyAssembly. XmlSerializers.dll to GAC and then to outlook folder, but had no success. When dll was called from GAC I got following error message, but dll has no any reference.
"System.IO.FileNotFoundException: Could not load file or assembly or
one of its dependencies. The system cannot find the file specified."
Please add any thoughts how can I to get rid of temporary dll
When an XmlSerializer for a type is first constructed, internally the XML serialization engine generates c# code to serialize and deserialize the type, writes it to %TEMP% in temporary file(s), then compiles and loads the resulting assembly, finally deleting any temporary files. (Subsequent usages of XmlSerializer reuse the created assembly, see here for details.)
It looks as though your antivirus software is being ultra-aggressive at scanning any "unexpected" files created by the Outlook process, immediately trapping the creation of the file and scanning the results. While under most circumstances this would seem praiseworthy, it clearly conflicts with Microsoft's design for XmlSerializer.
So, what to do about this? You have several options:
Switch to DataContractSerializer, which does not use this architecture. DataContractSerializer is less flexible that XmlSerializer, however, and may not be able to parse your XML without preprocessing it.
Enable precompiled serialization assemblies. It's not sufficient to simply set GenerateSerializationAssemblies = On as is specified in the documentation, you have to jump through several hoops to make this actually work. See answers to Generating an Xml Serialization assembly as part of my build for ways to do it. I was able to make the accepted answer work with my old Visual Studio 2008 by editing my project file as described and then removing the Platform="$(Platform)" attribute. You might need to tweak the answer differently for your VS version.
After actually enabling pre-generated serialization DLLs I verified with Process Monitor that no files were written to %TEMP% when deserializing XML in a test console application.
See also here: Boost performance with Pre-generated XmlSerializers.
Update
After a bit of testing, I found that, if your root object does not exist in the assembly you are building, or if is a generic collection like List<T> or T [], then precompiled serializer assemblies are not used. However, making a non-generic subclass of List<T> re-enables serializer assemblies, e.g. public class RootObjectList : List<RootObject> { }.
For more, see here: All about XmlSerializer Performance and Sgen.
Convert your XML to JSON with Json.NET, then deserialize the JSON.
If your XML is simple, you could load it into an XDocument and query it with Linq to XML.
We're developing a program that generates DOCX files using XML and transforms. Currently one person is responsible for development of the XML and XSLT files and another for the C# program that puts it all together. I'm the one developing the C# side. Using the .xslt file the transform works fantastic. The issue I'm having is that the manager of this project doesn't want me to distribute the .xslt's. Instead I'm compiling the file into a dll assembly. No I'm getting errors such as:
An error occurred while loading document ". See InnerExeption for a complete description of this error. This operation is not supported for a relative URI.
I know it's probably something simple I've probably missed. Does anyone know of a good article that outlines the implementation difference between using the xlst file and a compiled dll.
Thanks.
I'm trying to serialize some classes with protobufs. I installed protobuf-net using NuGet, properly decorated my code with the attributes, and everything is running great.
However, eventually messages will be created in C#, but consumed in other environments, so I need to either create .proto files from C#, or - what seems more reasonable to me - create C# code from .proto files.
No matter what I do, I can't find ProtoGen.exe installed anywhere in my computer. I also found this old post, but nothing of the sort happens when I create a .proto text file. Adding ProtoBufTool manually didn't work, either.
What am I missing?
Protogen is included in the v1/280 build, or there is a separate VS tool available from the project site. There isn't a convenient way to include it in nuget in any sensible way (I checked with MS folks; twice).
For both protogen and the VS addin, the functionality has not changed for v2, so the existing v1 binaries remain fine for use with v2.
If the ProtoBufTool didn't work then... I don't know what is up with that; was there any error message / warning? The classic warning is about the input file's encoding ("protoc", google's tool, is very fussy about encoding).
I'm trying to create a game editor using a C# form, and I've run into a problem when it comes to deserializing; I can't use the content pipeline in a forms application as I don't even have the option to add any content reference to the project. How can I use the content pipeline with my form app? Is there another way to load and deserialize my XML content?
Manually edit the .csproj file and add the following in the first PropertyGroup section which contains the assembly name, project guid etc.
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
You'll probably need to also add
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
Reload the project in VS, and you should be able to add content references to it.
The two GUIDs specified there are for Windows and XNA (Windows). Here is a list of some common project type guids (although slightly dated) if you need to retarget the project at all.
Take a look at the Winforms Series 2: Content Loading AppHub sample.
Basically you load and call appropriate microsoft.xna.framework.content classes to read your compiled xnb files.
You'd use classes in the namespaces within microsoft.xna.framework.content.pipeline to create the xnb files (which is what the content project would do for you).
See here for an overview of the content pipeline: What is the Content Pipeline?
Is there another way to load and deserialize my XML content?
Yes, use any .net method of serialising you want, maybe XDocument.
I've read that assembly serialization (sgen.exe) can improve performance.
What exactly is providing the improvement?
Is it metadata on the Types? I would have thought this would be available through reflection! so why is it required in a separate assembly?
The serialization assemblies Data.XmlSerializers.dll which improve the performance of clients that use XML Web service proxies to communicate with servers is described under http://msdn.microsoft.com/en-us/library/bk3w6240.aspx.
If you don't do this the same work will be done at the first usage of XmlSerializer. In the blog Link is described additional setting in <system.diagnostics> area of the application.config file to see more what do XmlSerializer in the background.
In Visual Studio there are a spetion setting in the "Build" tab of project settings (see http://www.eggheadcafe.com/tutorials/aspnet/8eb0e68f-5496-4363-9cb9-dd68447ba187/xml-serializer-generator.aspx). So you not really need to use sgen.exe manually.
To more understand what sgen.exe do you can load an open source version of sgen.exe: xgenplus http://xgenplus.codeplex.com/.
I recommend you aslo to read SGEN XMLSerializer - should be .XMLSerializers.dll added as a reference to the current project or to the GAC?.
If you search in google for XmlSerializer and sgen you will find all the information and even more on the first page of the serch results.