|
Update: revised code to use full Type names, not var; used hard-coded filepath.
Now, in VS 2019 using FW 4.8, File.Create terminates the app with no error message. I tried wrapping the call in a Try/Catch: terminates the app without ever reaching the Catch clause.
Note: i can't find any error reports on the behavior of File,Create described here.
A few years ago, the code shown here was a standard part of the serialization library i wrote, and worked fine. The other part of the library, which uses XML serialization, works without errors.
Note: the code shown compiles, but, fails in the first 'using block. File,Create moved outside the using statement also fails the same way. So, there's nothing specifically GZippy where the code fails.
// reqiured usings
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization;
public static void GZSerialize<T>(T instance, string baseFolderPath, string filename1)
{
dcs = new DataContractSerializer(typeof(T));
string fullfilename = baseFolderPath + "/" + filename1 + (usegzip + @".gz";
string fullfilename = @"C:\Users\Win-Ten\Desktop\fordata\test4.gz";
using (FileStream compressedFileStream = new FileStream(fullfilename, FileMode.OpenOrCreate, FileAccess.Write))
{
using (GZipStream compressionStream =
new GZipStream(compressedFileStream, CompressionLevel.Optimal, true))
{
dcs.WriteObject(compressionStream, instance);
compressionStream.Close();
}
}
}
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 8-Mar-22 16:14pm.
|
|
|
|
|
Do you know what the filename is at that point? I'm not sure what you were trying here, but that fullfilename creation line looks dodgy; it could just be the way you entered it here.
You don't need to delete a file before you call File.Create. If you call File.Create on an existing filename, it will overwrite the existing file.
|
|
|
|
|
Hi Pete,
Thanks, I double-checked using a hard-coded file name: same behavior observed; serializing to xml works, to gz closes app.
fyi: in output window after app closed: has exited with code 0 (0x0).
It may interest you to know that the original idea for my library came from code you posted here in 2015 in response to a question on serializing a TreeNode [^] Strange that I can't see your code for serializing on that thread now.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
I've tried your code with a hardcoded path and it works okay for me. The only failure I get is if I write to a protected location, or to a directory that doesn't exist.
|
|
|
|
|
Thanks, Pete,
Since saving XML to the same directory works, I can exclude the possible file errors you mention ... which I'd expect to throw errors.
Here's something really strange: after installing the latest VS 2019 Community update, to Version 16.11.11 ... the code worked once .. after that same behavior as before. Same app opened in VS 2022 latest: same fail.
There's one possible wild-card here i'll test today: PostSharp is installed in this solution (licensed version), although the code I am testing does not use it.
Will start a new solution w/o PostSharp and ReSharper turned off, and re-test.
cheers, Bill
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
|
Thanks, Richard, "process corrupted state" reminds me of what I see in the mirror these days
I'm retesting today in a new solution with PostSharp and ReSharper not in use.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
|
Thanks, David,
I think I can exclude that hypothesis based on the fact that using standard DataContract/DataMember serialization to XML to the same folder is reliable.
cheers, Bill
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Ok,
Just keep in mind that Windows Defender now performs behavioral analysis so it might allow certain actions while blocking others.
Good Luck. 
|
|
|
|
|
Thanks, David,
I have checked both Win-Def and EmsiSoft (my active malware filter/firewall), no evidence for this rather improbable scenario.
cheers, Bill
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Alright,
Then you should have no problems determining why your process is exiting. Did you try to attach a debugger? Did you check the event log and get the exit code[^]? Have you tried using Gflags[^]?
The path you gave in your top level post:
string fullfilename = @"C:\Users\Win-Ten\Desktop\fordata\test4.gz"; would be protected by controlled folder access (if enabled).
Best Wishes,
-David Delaune
|
|
|
|
|
@Randor
Thanks to David (aka Randor) !
Well, turns out I did not look deeply enough into the EmsiSoft AV/Firewall records, as David suggested.
Note: size of test file saved as .xml 1017; size saved as .gz 369.
EmsiSoft was quarantining the WinForm app .exe. I set permission for the entire folder containing my C# work in progress ...code works ... ... setting permission for VS 2019 and 2022 had no effect. Why the whole folder ? I was too lazy to set it for one specific project.
Here's what the kinks were:
1. no run-time notification pop-up from EmsiSoft which is normally ... a frequent popper-upper. And, once quarantined, why should the app run partially at all ? I will write about this to them, and, aaso ask them what could happen if I were using GitHub storage.
2. why should standard XML writing:
using (var writer = new FileStream(fullfilename, FileMode.OpenOrCreate, FileAccess.Write
))
{
dcs.WriteObject(writer, instance);
} work, but, why does this:
using (FileStream compressedFileStream = new FileStream(fullfilename, FileMode.OpenOrCreate, FileAccess.Write))
{
using (GZipStream compressionStream =
new GZipStream(compressedFileStream, CompressionLevel.Optimal, false))
{
dcs.WriteObject(compressionStream, instance);
compressionStream.Close();
}
} trigger AV interception ? Is there an MS bug here ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 11-Mar-22 6:08am.
|
|
|
|
|
Happy to see you solved it. 
|
|
|
|
|
@Randor
Well, Sir, i think it is ... You ... who solved it !
But, please indulge my OCD re language: i do consider understanding the source of an anomaly as not equatable with "solved." Yet, it was moi who used thr word "solved: End of rant.
What a wonderful education code that worked for years ... and then, breaks ... can offer
Please come to Chiang Mai asap so i can take you for a scrumptious Thai dinner.
cheers, Bill
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 12-Mar-22 3:58am.
|
|
|
|
|
Queues:
A queue is a "first in first out" data structure. Inserting elements is called 'enqueuing'.
Removing/deleting elements from a queue is called 'dequeueing'.
If you enqueue (insert) elements in this order, then when you call dequeue, the
first element removed is . The second element would be and so on.
Input:
Each input line will look like one of the following:
E \n
D\n
where is a number that will fit inside int on the server.
Goal:
Maintain a queue of elements. Enqueue elements when input starts with "E". Dequeue when
the input line is "D".
Output:
If the input line said "E ", then enqueue (insert) the number into . No output!
If the input line said "D", then dequeue from and print the number that was dequeued.
If a dequeue was requested on an empty queue, print "Empty".
Terminate all your output lines with \n .
Implementation Rules:
You must use a struct to maintain your queue.
Use convenient typedef(s).
Create supporting functions.
Although in practice, you would create separate header file(s), we require you to put everything
into just one .c file so that our evaluation server can be used.
|
|
|
|
|
You forgot to ask a question. Just posting your homework assignment is kind of useless.
|
|
|
|
|
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi everybody,
I am using Vs 2019 and i am trying to use crystalreport, but there is not way (that i know) how to do that the CystalReportViewer displayed in the toolbox correctly.
If it is displayed its doesn't work.
My questions are:
1. Is there is a way how to do this?
2. Is there is a way to display the report without using reportviewer?
P.D; the App is in windows form.
Thanks in advance
|
|
|
|
|
When I used CR spit, 15 years ago I would prepare the dataset in code and use a local reportviewer (not connected to the database) and pass the prepared data to the viewer, it was a PITA while creating the report but made deployment and management easier. I gave up CR when their support took 15 months to reply to a support ticket.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
public List<T> DatasettoList<T>(string commandText, CommandType commandType, IDbDataParameter[] parameters = null) where T : class, new()
{
DataSet dataSet = new DataSet();
if ((commandType == null) || (commandText == null) || (commandText.Length == 0))
{
throw new Exception("Invailid command");
}
dataSet = GetDataSet(commandText, commandType, parameters);
if (dataSet.Tables.Count == 0)
{
return null;
}
if (dataSet.Tables[0].Rows.Count == 0)
{
return null;
}
ProposalDownloadView prop = new ProposalDownloadView();
List<ProposalDownloadView> proplist = new List<ProposalDownloadView>();
List<T> list = new List<T>();
var myData = dataSet.Tables[0].AsEnumerable().Select(r => new
{
UserId = r.Field<string>("UserId"),
UseProposalNorId = r.Field<int>("UseProposalNorId"),
FromDate = r.Field<decimal?>("FromDate"),
ToDate = r.Field<decimal?>("ToDate")
}).ToList();
list = myData.ToList();
return list;
}
I am unbale to return list after above code third list line creates error. Please help. Thanks in advance
|
|
|
|
|
You forgot to tell us what the error is.
But in this case, it's pretty obvious: you have a List<> of an anonymous type. Calling .ToList() on that will return exactly the same thing - a list of your anonymous type. You cannot magically treat that as a list of T .
It looks like you've copied a couple of different code samples from somewhere and tried to mash them together without understanding what they're doing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I’m making a windows form project, I made a method to play a music and I put that method in form1 so when the game starts it can play the music but I have other sounds effects in the game also so when I hit space for shooting it cuts the background music that is playing and stays just the sound of shooting or explosions sounds but the music never gets to play again until I restart the game.
What should I do for when the music keeps playing it also makes the shooting and explosion sounds
|
|
|
|
|
How would we know, without any idea what your code is doing?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you are using MediaPlayer, you will be pleased to know that it doesn't need to be dispatched onto the main thread. What you could do is have separate threads for your music and your sound effect. When the sound effect needs to play, you would signal it and it would play on the other thread. This should result in both of your sounds playing together.
|
|
|
|
|