Published WPF Program Unable To Run
I've been working on a version one of my project for a while now, and i've finally got it to the point where I could publish a version one.
However, the version one I published doesn't actually run, and using the event editor I get a large error. I was wondering if anyone here can translate what exactly is wrong with my program that is causing it to crash?
53 Replies
Can you maybe post the error in a format which isn't one massive impossible-to-read line?
That's just the output in a .txt file.
https://pastebin.com/QkAf1Juk
Pastebin
>Application: Paradox Editor.exe CoreCLR Version: 6.0.522.21309 .NE...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Here's the same thing but in pastebin.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
The original will have line breaks in, at least
But, looks like you're code is trying to access that wav file by path, but that file isn't being included in your published application, or it isn't at the path that you're application's expecting it to be at
Well, reading that error the closest thing I can estimate would be the cause would be:
In debugging/testing, this code works perfectly fine. Seems like it breaks in publish.
Hard to say more without knowing how you're trying to package that file, and how you're trying to load it
These are the publish settings I've set.
Well for starters don't use the current directory like that -- it can be set to whatever the user wants it to be set to, which might well not be the directory containing your application
What should I set it do?
Sorry, oven's beeping. Back tomorrow
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'll try that out
I don't believe its working, even with this change.
In testing this works perfectly, but not in publish.
Are you sure that those wav files are being included in the publish?
Presumably you've set them as 'Build Action' = 'None', 'Copy Local' = 'If Changed'?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
The files are within my project, so the bin directory
All are set to be copied*/added Content.
They are included in the publish.
All of the
Parent
s there suggest you're not referencing it from the bin directory though?
Don't think they need to be Content? Just copied to the bin dirI believe I was attempting to just get the directory of the wav files which would be included within the project
Why are you going up so many levels? The wav file and the executing assembly should be in the same folder, next to each other?
I'll be damned if I can understand why I put it that way. I guess it was to have it work in testing
I don't remember how to set it to the executable's directory
Like I say, I think you're referencing the wav file in your source dir, not the one that's copied to your bin dir
So fix that, and you should be good?
How would I do so?
Change this to construct the path to your bin dir?
this leads me directly to the bin directory.
are you sure about that? I don't see why you need two
.Parent
s
And how are you using that? Can you show how you contruct the path to the wav file?Alright, 1 moment
Then it is used here
var soundDirectory = new Uri(WorkingDirectory + SoundAssetsPath + "connecting.wav", UriKind.Relative);
(nit, use
Path.Join
to join paths)
And what's the value of soundDirectory
?
Now you've got three parents
I normally do Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
or similarSound directory is meant to be the project -> sound assets (which is assets -> game -> sound)
What is the actual, literal value, if you inspect it in a debugger?
So for context first, this is the set working directory code as of current:
private static string WorkingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Its value is :
"C:\\Users\\LukeZurg22_Gaming\\source\\repos\\Paradox Editor\\bin\\Debug\\net6.0-windows"
Sound directory's value, when the initial sound is called is:
{C:\Users\LukeZurg22_Gaming\source\repos\Paradox Editor\bin\Debug\net6.0-windows\Assets\VIC2\Sounds\validClick.wav}
These are values gotten during debugging.You've taken off all of those
.Parent
calls there?Absolutely
Works the same as
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
OK, so does that work now?
It very much doesn't do the same thing as what you had before, heh
Well, in debugging, yes. But not in publish.
One minute, I'll try a full recompile.
You can debug the published exe as well - you can point vs at an exe to start, or attach it to a running process
Debugging the release and debug versions work just fine. But the published version of the program : nada.
Aah it's self contained
I missed that
Not sure what happens to stuff that's just set to copy local. They might get extracted with the rest of the bundle, but GetExecutionAssembly gives you the wrong path?
Does the wav get copied to the publish folder?
Do you need it as a separate file even? Can you make it an EmbeddedResource, and load with GetManifestResourceStream?
The wav files are copied to the published folder.
There are multiple different wav files of the same same, under different folders
Looks like you might be able to use
AppDomain.CurrentDomain.BaseDirectory
to get the right path?I'll try that
Looks like you might need IncludeAllContentForSelfExtract too?
Making them embedded resources rather than free files will probably be easier imo
How would I set it to do that?
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
in an appropriate place in your csprojGood god, that was the ticket.
However you say they would be better as embedded resources?
Hah! Nice
I tend to prefer them if possible - embedding everything the exe needs inside the exe is just neater than having a load of free files knocking around
Agreed
(which can go missing, or be snaffled up by av, or not deploy properly (as you've seen))
I tried working with getting the resources put into the program itself, but hadn't had luck
Embedded Resource, not Resource, confusingly
How would I process embedded resources if they weren't proper files?
Simple setting them to embedded causes the program to go nuts, as it can't locate them otherwise.
You have to load them with
Assembly.GetManifestResourceStream
That gives you a Stream