C
C#15mo ago
Marvin

Issue with FolderBrowserDialog in console application

Hey, when I start my application via Visual Studio everything works, but as soon as I start the console application directly, I get the following error:
System.MissingMethodException: Method not found: 'Void System.Security.Permissions.RegistryPermission..ctor(System.Security.Permissions.PermissionState)'
System.MissingMethodException: Method not found: 'Void System.Security.Permissions.RegistryPermission..ctor(System.Security.Permissions.PermissionState)'
Code:
public static void OpenFileDialog()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == DialogResult.OK)
{
foreach (var path in Directory.GetFiles(fbd.SelectedPath))
{
Console.WriteLine(path);
}
}
}
public static void OpenFileDialog()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == DialogResult.OK)
{
foreach (var path in Directory.GetFiles(fbd.SelectedPath))
{
Console.WriteLine(path);
}
}
}
20 Replies
phaseshift
phaseshift15mo ago
console runtime does not have access to ui stuff. If you want UI, don't pick a console project
Marvin
Marvin15mo ago
but why then via visual studio?
phaseshift
phaseshift15mo ago
wat
Marvin
Marvin15mo ago
if i start the application with visual studio stuff (image), then it works.
Marvin
Marvin15mo ago
Marvin
Marvin15mo ago
and yup, it have the STAThread Attribute
phaseshift
phaseshift15mo ago
Oh. Are you copying your app to another machine or something?
Marvin
Marvin15mo ago
later then, not yet so yes, it is planned that others can use the programme. currently, however, it is only local to me. if that's what you meant
phaseshift
phaseshift15mo ago
Yes. What SDK/.NET version are you using ?
Marvin
Marvin15mo ago
netcoreapp3.1
phaseshift
phaseshift15mo ago
GitHub
MissingMethodException for System.Security.Permissions.SecurityPerm...
Looks like the issue I opened in https://github.com/dotnet/coreclr/issues/21742 probably belongs here. New in .NET Core 3.0 Preview 1 compared to 2.2 is a MissingMethodException for Void System.Sec...
phaseshift
phaseshift15mo ago
Seems relevant
Marvin
Marvin15mo ago
old stuff i think
Marvin
Marvin15mo ago
phaseshift
phaseshift15mo ago
yeah
Angius
Angius15mo ago
.NET Core 3.1 is old stuff, indeed
phaseshift
phaseshift15mo ago
or just update your net core 'net core' -> net 7
Marvin
Marvin15mo ago
sad will it fix the issue? 😂
Angius
Angius15mo ago
If it will - great If it won't - still great, you're up to date at least
Marvin
Marvin15mo ago
lol its not supported by them, but i never had issues like that. but im sure, it will change nothing xd whatever, thank you all