|
Hi, OriginalGriff.
I used the code you wrote in your article, but I received an error message. First see a snipet of my code:
public static Guid AppGuid
{
get
{
Assembly asm = Assembly.GetEntryAssembly();
object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
return new Guid((attr[0] as GuidAttribute).Value);
}
}
This is in fact your code. The error is on the line of the return:
"System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'"
Do you know what causes this error?
Thanks.
|
|
|
|
|
That's because your app doesn't have a GuidAttribute.
Go into your project Properties, click on the Application tab, then Assembly Information button. You'll find a GUID box in the dialog that pops up. That box is empty. That's where you have to put your GUID.
|
|
|
|
|
Normally, that is filled in by VS when it creates the project template. Dunno what he used to do that ...
"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!
|
|
|
|
|
Under the .NET Framework projects (4.8 at least), it's filled in by the Windows Forms template, but not the WPF template. I haven't tried any of the others.
On .NET Core projects, the "Assembly Information" option doesn't even exist. The assembly info is automatically generated at compile time, but is controllable in the .csproj file.
I haven't spent very much time looking at this because I don't expose much to COM, so YMMV.
|
|
|
|
|
Hi, Dave.
I tried here, but didn't get it. I use VS Community 2022 in portuguese.
In my superior menu there is "Tools" and then "Create GUID". Next appears a small form with many options (1 - IMPLEMENT_OLECREATE(...) 2 - DEFINE_GUID(...) and others). Menu says I must copy and paste the chosen option in my source code. But I don't understand what I should do. Have you seen this? Can you help me? Thanks again.
|
|
|
|
|
Pick Registry format, click the Copy button, then you go back into the Project Properties, ..., and paste that value into the GUID box and click OK.
|
|
|
|
|
Dave. For me there is no GUID box. But I'll tell yu my original problem, and maybe you can give another tip. I'll install a desktop application for a client and need to store the instalation folder somewhere. Inicially I thougt of using windows registry, but the local available was CURRENTUSER, and I didn't like it. Then I read OriginalGriff's article and thougt of a text file anywhere I can find and the ALLUSERS folder appeared to be good for me. Then these problems arouse.
Do you have any suggestion? Thanks a lot.
|
|
|
|
|
What type of app are you writing, which version of .NET or the .NET Framework are you writing this code against, and are you exposing any components in your app to COM?
|
|
|
|
|
I'm writing a program to control incomes and expenses of a small company. .NET Framework version 4.8.04084. Microsoft Visual Studio Community 2022 Version 17.2.6
Is this what you wanted?
|
|
|
|
|
OK, so you're writing either a Windows Forms app, or WPF, for some accounting function.
You have no reason at all to be saving anything to HKEY_LOCAL_MACHINE. Follow the advice of Griff.
As for the Guid of the app, you really have no use for it so why are you interested in it?
|
|
|
|
|
Hi, Dave.
I changed my approach. Now I get a special folder path and will use it to store a text file containing the installation folder of my app. The command is:
string caminho = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToString();
I think it will solve my problem.
Thanks for your help and interest!
|
|
|
|
|
GetFolderPath always returns a string, so why are you calling .ToString() on a string?
|
|
|
|
|
You do not need to store that. You can get that info at runtime.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi, Eddy.
How can I obtain the installation folder of an application? Note that I need it from another application, not the one running at this moment.
Thanks.
|
|
|
|
|
And it's prolly not an application that you launched, so it is a running app that you did not launch?
Does the app have a windows handle? Then you can get the executables location.
https://www.autohotkey.com/boards/viewtopic.php?t=69925[^]
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
hello everyone, I'm a young developer c#, I'm using dapper for data manipulation, I have a database on which making a particular query I get 100K + 18 rows that will have to be exported to excel . The problem lies in the fact that, to get the results, it takes almost 12 minutes....to have array_channel_list[i],Can you speed it up in some way ?thank you very much! (sorry for my bad english)
<pre>
List<string> query = new List<string>();
List<EntityFramework.Channels>[] array_channel_list = new List<EntityFramework.Channels>[dim];
using (var conn = new SqlConnection(connection))
{
for (int i = 0; i < dim; i++)
{
query.Add("SELECT ID, matricola, disegno, descrizione, nodeid, result, coppia, angolo, prgnr, prgname, date, NomeFile, lastcmd, laststeprow, laststepcolumn, qualitycode, rootobj_ID FROM dbo.Channels where rootobj_ID IN (" + string.Join(",", array_id[i]) + ") ORDER BY ID");
try
{
array_channel_list[i] = conn.Query<EntityFramework.Channels>(query[i], commandTimeout: queryTimeoutInSeconds,buffered:false).ToList();
}
catch (SqlException error)
{
Console.WriteLine("Errore: " + error.ToString());
}
}
}
|
|
|
|
|
Without access to your DB and any idea what the query results look like, we can't really help much - except to say that multiple SELECT queries aren't a particularly fast way to do it: you may get significant improvements by issuing a single request and post-processing the data locally in memory.
I'd start by profiling the code to find out where the time is being taken: if nothing else, the Stopwatch class should be able to give you a good idea where your bottle necks are, though you may have to "break up" that code to start getting any meaningful results as method chaining makes any profiling pretty difficult.
"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!
|
|
|
|
|
Antennista Televes wrote: query.Add("SELECT ID, matricola, disegno, descrizione, nodeid, result, coppia, angolo, prgnr, prgname, date, NomeFile, lastcmd, laststeprow, laststepcolumn, qualitycode, rootobj_ID FROM dbo.Channels where rootobj_ID IN (" + string.Join(",", array_id[i]) + ") ORDER BY ID");
Don't do it like that!
Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
Beyond that, your question is not clear. Your code mentions Entity Framework, but you seem to be using a method from Dapper[^]. You haven't explained what array_id contains. You haven't explained why you're loading an array of List<T> instances. And you don't appear to have profiled your code to find out which part is slow.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You've got dates and names in your query; and no grouping / summing or range checking.
It's basically a "data dump" and not a meaningful query in any sense of the word.
You need to ask yourself at some point: Why am I running this query? Why am I not using a stored procedure?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I wish to write a program like Quicken, only better. I am having trouble finding a control that looks like a check register. Does anyone know of such an animal?
Thanks in advance!
|
|
|
|
|
What the heck is a "check register"? Without using Quicken - which I don't - we have no idea what you are after.
And to be honest, copying the "look and feel" of an app but making it "only better" is probably not a good idea - it's asking for corporate lawyers to start writing you some very unpleasant letters ... in much the same way that coming out with a new soft drink in a red can called "Caca Cola" would .
I'd suggest that you think about what the original does well, work out ways that can be done better, and then design your own unique UI to makes the whole task easier for the user - then start designing the new app.
"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!
|
|
|
|
|
For such a specialized application, you're most likely not going to find such an animal.
You'll probably have to write your own control for that.
|
|
|
|
|
I am wondering if someone or some company already has. I do not know how to write a control, and I really don't want to take the time to learn it right now.
I thank you very much for your input! 
|
|
|
|
|
It would benefit you greatly to learn how to write controls. This will come up a lot more often then you think.
|
|
|
|
|
Quote: I do not know how to write a control, and I really don't want to take the time to learn it right now.
So ... your app is going to be largely bits of stuff you don't understand slammed together with a lot of "I hope it works" glue?
When something goes wrong, how do you propose to work out where the problem is, let alone how to fix it?
"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!
|
|
|
|
|