|
Next question is:
I found some stuff to enumerate the GAC, but what I want is something that looks more like VS's Add Reference dialog. There are two interesting things going on in this list:
1. It shows the path to the installed assembly, not the GAC path
2. It only shows assemblies relevant to the current compiler version.
How the heck does it do that? I've looked around for a couple months, off and on, and have never found the answer!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
It has nothing to do with the GAC. See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders.
I hope I'm not asking a really dumb question here--I have entries in that registry key, but there's no "data"--only folders with the names of the assemblies.
So, the question is, how do I take that information and obtain the actual assembly path?
Thanks!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Enumerate the sub-keys and grab the default value of each sub-key. Enumerate each directory to load the assemblies:
using System;
using System.IO;
using Microsoft.Win32;
class Test
{
static void Main()
{
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\.NETFramework\AssemblyFolders"))
{
foreach (string key in rk.GetSubKeyNames())
{
using (RegistryKey af = rk.OpenSubKey(key))
{
string dir = (string)af.GetValue(null);
if (Directory.Exists(dir))
{
Console.WriteLine("Enumerating \"{0}\"...", dir);
foreach (string file in Directory.GetFiles(dir, "*.dll"))
{
Console.WriteLine(file);
}
Console.WriteLine();
}
}
}
}
}
} If you want to check the version of the runtime the assembly uses, you could load it and see which version of mscorlib.dll is required. If this application will be running for a while (like Visual Studio), then you should consider creating a new AppDomain to do this since you cannot unload assemblies and don't want to have all those assemblies loaded for no reason.
Instead of loading the assemblies, you could also load the PE/COFF images and determine the information yourself. You could use IL Reader[^] (from Lutz Roeder, creator of .NET Reflector) to inflect what that could be and not load the assembly into an AppDomain at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Oh God, I'm an idiot. I had the data name column set so wide on my registry view that I didn't even see that the default value had any content.
Major embarassment here.
Thanks for the other feedback regarding figuring out what version of mscorlib.dll is required. That's definitely something I didn't realize!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Is it possible for a dll to call dll? What I'm doing is creating few dll, along with one standard.dll. For example, those dlls (111.dll, 222.dll, 333.dll, 444.dll, 555.dll) would call a single function from standards.dll. So that the function in standard.dll would be consistent with those 5 dlls. It will save time rather than having to recompile all of those 5 dlls after revising the standard.dll.
I have created the application which passes the string variable over to the dll then one of those 5 dll would be used (depending on the data). I hope that I have explained clearly.
I've been using Visual.Net C# language to do this. I am able to communicate with one of those 5 dlls, but unsure how to do this to have one of 5 dlls to communicate with standards.dll. I am also hoping to have standard.dll to be separate from those 5 (not to be built in but separeate.)
|
|
|
|
|
DLLs don't "call" other DLLs, but they do reference them. Assemblies can reference each other, and you can even have circular references (it's very tricky, though, and requires pretty good knowledge of the DLLs - but Types can't be circular), but not in Visual Studio .NET.
Your types in other DLLs (assemblies are what they actually are in .NET) must be public in order for Types in other assemblies to use them. This is no different than when you reference assemblies from the Base Class Library (BCL), like System.Windows.Forms.Form for Windows Forms, or System.Web.UI.WebControls.Control for ASP.NET web controls.
Using VS.NET, you can add references to .NET assemblies, COM libraries, and even other projects in the same solution. Right-click on your project and select Add Reference. Use project references when possible (with multi-project solutions) to establish build dependencies.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
The poor guy is probably trying to do some type of plugin architecture... maybe couldn't express himself correctly.
In that case he can start digging through Reflections
|
|
|
|
|
I've got it!
I've used the dll's (not the standards.dll) to be called by late binding of dll's (see sample code below
----
String PassToDll("FFEEFF1A");
String path = "abc.dll";
Assembly a = Assembly.LoadFrom(path);
Type mm = a.GetType("abc");
object o = Activator.CreateInstance(mm);
object [] par = new object[] {PassToDll};
edtDllResult.Text = mm.InvokeMember("InterpretCrumData", BindingFlags.Default | BindingFlags.InvokeMethod, null, o, par).ToString();
----
then I created abc.dll by creating a new library. I added the reference for Standards.dll.
then sample code in abc.dll
----
using System;
using Standards_Dll;
//namespace abc_Dll
//{
///
/// Summary description for Class1.
///
public class abc
{
public abc()
{ // TODO: Add constructor logic here // }
public int InterpretCrumData(string readtext)
{
// snip code
return (<variable>);
}
}
// }
----
So now I am able to make more dll's for this.
|
|
|
|
|
hey all,
I'm somewhat new to C# programming. Basically I want to send the current day that the program is executed on (Monday, Tues, Etc.) to a variable, and then to a text box (textBox1). here is what I have so far to run when the form loads.
if (day = DateTime.Today.DayOfWeek.Equals(Monday))<br />
this.textBox1.Text = "It is Monday!";<br />
else<br />
{<br />
}
I also added the namespace (I think its called)
private System.DateTime day;
so what's wrong with the code? any help would be awesome.
I know I have a lot of learning ahead, so don't worry about the criticisms
happy programming,
Stephen
|
|
|
|
|
I think what you want is:
if (DateTime.Today.DayOfWeek==DayOfWeek.Monday)
{
...
}
There's no reason to use "Equals", but if you want to, you probably have to say "Equals(DayOfWeek.Monday)" to properly reference the enumerator.
Also, the "day=" assignment doesn't make any sense. Is "day" a boolean? Because that's what the Equals returns.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
awesome, thanks a lot for the help.
-Stephen
|
|
|
|
|
just a thought (not at a computer with a programming environment atm)
Does this work:
<br />
this.textBox1.Text = "It is " + DateTime.Today.DayOfWeek.ToString() + "!";<br />
(You'll probably have to fiddle syntax, as that's just off the top of my head)
I've noticed all these ToString members everywhere - dunno if it'd work properly with an enum like that, but it seems to be what it's intended for!
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
I'm trying to use a animated GIF file on my splash screen. The GIF is placed inside of a picture box. The picture shows fine but the animation doesn't work. When I use the GIF in any other form the animation works. It just won't work on the splash screen. Any Ideas?
|
|
|
|
|
There could be several things wrong, but you need to be more specific about how you're dealing with your splash screen, since it could be implemented in countless different ways.
The important thing is that you always modify a control - like change the PictureBox.Image property if that's what you're doing - in the thread on which the control was created. You can do this using the InvokeRequired property and the Invoke method, both of which include an example of using them (they're defined by the Control class and, thus, inheritted by every derivative class).
If you're doing this on a timer's event handler (like the System.Windows.Forms.Timer component), than you are doing this in a different thread and the results are undefined.
This is, most likely, the problem you're having.
Now, if you mean the GIF is animated and your PictureBox isn't animating it, please post some additional code to help us understand how you're using the control.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
hello techies,
I written a C# application which executes few stored procedures against the database(MSsql 7.0) .While executing stored procs thru my appln, sometimes it throws sql exception saying "Time expired when running the scripts". But it happens only 2 out of every 10 test runs..
Is there a way to overcome this problem
rgds,
jagan
ps; I donot have that many connections to SQL server as well.
|
|
|
|
|
Time your stored procedure. One very simplistic way is something like this:
DateTime start = DateTime.Now;
try
{
connection.Open();
command.ExecuteNonQuery();
}
finally
{
connection.Close();
TimeSpan span = DateTime.Now - start;
} Again, this is very simplistic.
If you need to adjust your timeout for the command (not for the connection, which probably isn't the problem) - and do so intelligently since changing the timeout for invalid commands can make your program take needlessly longer to return in err - then change the CommandTimeout property of whatever IDbCommand implementation you're using (like SqlCommand ).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
invalid commands can make your program take needlessly longer to return in err
Heath - what do you mean by "invalid command"? The call to the DB should return as soon as the DB is done processing it, regardless of the timeout right? So if the command is invalid, wouldn't the DB return some type of syntax error immediately?
Well, now that I think about it, if the application allowed the user to enter an arbitrary query, I guess the user could do something silly that took forever to execute which would effectively hang the app until the timeout was reached. Is this the type of situation you are referring to?
Brian
|
|
|
|
|
Brian Nottingham wrote:
Well, now that I think about it, if the application allowed the user to enter an arbitrary query
Unless you're writing some database management tool, an application should never let a user enter an arbitrary query. There should always be some kind of control over what the user can enter.
"Invalid commands" may be a little overly broad but consider cases where a stored proc might connect to a remote data store (another database, XML, etc.). "Invalid command", depending on the scope of the problem, could also mean that the condition is to general and would select too many records for the intended use of the data. It doesn't necessary mean there's a syntax error.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
an application should never let a user enter an arbitrary query
Totally agree.
Heath Stewart wrote:
select too many records for the intended use of the data
I guess thats what i was getting at, but with the added twist that the user was allowed to enter it. The programmer should have an idea of the data the database may contain, and write the queries appropriately. If you know its going to take a while, increase the timeout. Which is what you already said a few posts ago, so... yeah...
Brian
|
|
|
|
|
Unfortunately, most programmers are human and not only make mistakes but can't account for every possibility. Many uses for Code Access Security are to ensure that code isn't used inappropriately - protection against such a check.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thank you guys.. would get back to after i try out this option..
cheers,
jagan
|
|
|
|
|
Hello folks,
The latest project involves a collection of large (multi-MB) images; I'm working on set of controls including an interactive thumbnail display and an image list; when the user selects an item in the list, a thumbnail is highlighted. When the user clicks a thumbnail, the corresponding item is selected in the list.
The problem here is that I load Bitmaps for each image, and then just draw them in a small rectangle. So I've got these huge hogging Bitmaps drawing in little spaces leading me to believe I'm wasting memory. Is there some way you can get a "low quality" thumbnail of a massive image file without loading the entire file into memory? "Skim" the file, or something like that.
If that is really difficult, is there a way I can load the huge files into memory only initially and just store them as tiny thumbnail Bitmap objects? Thanks!
--
vir·tu·al re·al·i·ty
n. Abbr. VR
A computer simulation of a real or imaginary universe in which Microsoft APIs are thoroughly documented and behave in an entirely logical manner.
|
|
|
|
|
If you load the images into memory and draw them into a smaller bitmap, then call the dispose method of the larger ones, that will do the trick. I dunno of an efficient way to read the file off disc and build a smaller bitmap, but I guess it may be possible. Scanning the file to build a smaller bitmap is easy, I just dunno how the disc access part would work, or if it would be faster to seek to individual bytes, as opposed to reading the whole thing in one go.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Just a thought:
Windows Explorer is able do create thumbnail display for most file types these days. If you can programmatically invoke the process, you will get the ‘thumbs.db’ file. Using some API you would be able to able to read it and show the thumbnails without wasting much resources. Search in this direction.
Second way: You can have a service which creates thumbnails for all files in a predefined folder, like google’s picasa. You can use a third party library to generate the thumbnails. I believe there are free libraries for this purpose. (ImageGear is a library I worked on, but its not free)
Hope this gives a direction.
|
|
|
|