C
C#3y ago
LukeZurg22

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
canton7
canton73y ago
Can you maybe post the error in a format which isn't one massive impossible-to-read line?
LukeZurg22
LukeZurg22OP3y ago
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.
LukeZurg22
LukeZurg22OP3y ago
Here's the same thing but in pastebin.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
canton7
canton73y ago
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
LukeZurg22
LukeZurg22OP3y ago
Well, reading that error the closest thing I can estimate would be the cause would be:
public static string SoundAssetsPath = @"/Assets/VIC2/Sounds/"; //The Resource Path for the Icons
private static string WorkingDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName;
public static string SoundAssetsPath = @"/Assets/VIC2/Sounds/"; //The Resource Path for the Icons
private static string WorkingDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName;
In debugging/testing, this code works perfectly fine. Seems like it breaks in publish.
canton7
canton73y ago
Hard to say more without knowing how you're trying to package that file, and how you're trying to load it
LukeZurg22
LukeZurg22OP3y ago
These are the publish settings I've set.
canton7
canton73y ago
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
LukeZurg22
LukeZurg22OP3y ago
What should I set it do?
canton7
canton73y ago
Sorry, oven's beeping. Back tomorrow
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
LukeZurg22
LukeZurg22OP3y ago
I'll try that out I don't believe its working, even with this change.
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
In testing this works perfectly, but not in publish.
canton7
canton73y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
LukeZurg22
LukeZurg22OP3y ago
The files are within my project, so the bin directory All are set to be copied*/added Content. They are included in the publish.
canton7
canton73y ago
All of the Parents 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 dir
LukeZurg22
LukeZurg22OP3y ago
I believe I was attempting to just get the directory of the wav files which would be included within the project
canton7
canton73y ago
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?
LukeZurg22
LukeZurg22OP3y ago
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
canton7
canton73y ago
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?
LukeZurg22
LukeZurg22OP3y ago
How would I do so?
canton7
canton73y ago
Change this to construct the path to your bin dir?
LukeZurg22
LukeZurg22OP3y ago
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.FullName;
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.FullName;
this leads me directly to the bin directory.
canton7
canton73y ago
are you sure about that? I don't see why you need two .Parents And how are you using that? Can you show how you contruct the path to the wav file?
LukeZurg22
LukeZurg22OP3y ago
Alright, 1 moment
LukeZurg22
LukeZurg22OP3y ago
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
Then it is used here var soundDirectory = new Uri(WorkingDirectory + SoundAssetsPath + "connecting.wav", UriKind.Relative);
canton7
canton73y ago
(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 similar
LukeZurg22
LukeZurg22OP3y ago
Sound directory is meant to be the project -> sound assets (which is assets -> game -> sound)
canton7
canton73y ago
What is the actual, literal value, if you inspect it in a debugger?
LukeZurg22
LukeZurg22OP3y ago
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.
canton7
canton73y ago
You've taken off all of those .Parent calls there?
LukeZurg22
LukeZurg22OP3y ago
Absolutely Works the same as private static string WorkingDirectory = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
canton7
canton73y ago
OK, so does that work now? It very much doesn't do the same thing as what you had before, heh
LukeZurg22
LukeZurg22OP3y ago
Well, in debugging, yes. But not in publish. One minute, I'll try a full recompile.
canton7
canton73y ago
You can debug the published exe as well - you can point vs at an exe to start, or attach it to a running process
LukeZurg22
LukeZurg22OP3y ago
Debugging the release and debug versions work just fine. But the published version of the program : nada.
canton7
canton73y ago
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?
LukeZurg22
LukeZurg22OP3y ago
The wav files are copied to the published folder. There are multiple different wav files of the same same, under different folders
canton7
canton73y ago
Looks like you might be able to use AppDomain.CurrentDomain.BaseDirectory to get the right path?
LukeZurg22
LukeZurg22OP3y ago
I'll try that
canton7
canton73y ago
Looks like you might need IncludeAllContentForSelfExtract too? Making them embedded resources rather than free files will probably be easier imo
LukeZurg22
LukeZurg22OP3y ago
How would I set it to do that?
canton7
canton73y ago
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> in an appropriate place in your csproj
LukeZurg22
LukeZurg22OP3y ago
Good god, that was the ticket. However you say they would be better as embedded resources?
canton7
canton73y ago
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
LukeZurg22
LukeZurg22OP3y ago
Agreed
canton7
canton73y ago
(which can go missing, or be snaffled up by av, or not deploy properly (as you've seen))
LukeZurg22
LukeZurg22OP3y ago
I tried working with getting the resources put into the program itself, but hadn't had luck
canton7
canton73y ago
Embedded Resource, not Resource, confusingly
LukeZurg22
LukeZurg22OP3y ago
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.
canton7
canton73y ago
You have to load them with Assembly.GetManifestResourceStream That gives you a Stream
Want results from more Discord servers?
Add your server