|
I would appreciate any help with the following situation:
I have a solution with two projects. The first project creates a .dll that is referenced by the second one, which contains some classes that derive from interfaces defined in the first .dll.
The problem is that in Visual Studio, when I try to compile the second project, I get an error saying that the first .dll does not have a strong name and because of this, I cannot derive my classes from its interfaces. In the real world, this .dll will be in the same directory than the executable, so there is no need to sign it. In Visual Studio, the first .dll is in a different directory and I cannot copy it to the /bin/debug folder because everything is removed from that directory when the second project is compiled...
Thanks in advance for your help.
|
|
|
|
|
A strong name assembly has a version and public key token, and you should always build assemblies as such in order to stick them in the GAC, enable assembly binding redirection (handle for upgrades), better code access security through simplified evidence, and much more!
Generate a key pair using
sn.exe -k KeyFile.snk Keep this somewhere safe. In your projects (presumably in the AssemblyInfo.cs file), add the path to that key file in the AssemblyKeyFileAttribute , or if you added it to a container using
sn.exe -i KeyFile.snk MyContainerName put that name in the AssemblyKeyNameAttribute .
Also make sure that the AssemblyVersionAttribute has a value, but I highly recommend both from lots of experience and from Microsoft's own recommendations not to use automatic versioning (via the asterisk) in multi-project solutions because versioning can get out of hand VERY quickly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have the following two code segments on different pages. On Page A (dlEvents) I get the following error "Object reference not set to an instance of an object." On Page B (dlCourseDetails) the code works fine. I have checked the control ID's to make sure they are correct. The data on the database is identical. Both pages have DataLists. In addition, I'm now having a similar problem casting a TextBox on another page. I'm stumped! Has anyone run into this? Does anyone know why it would work fine on one page and blow up on the other?
private void dlEvents_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)<br />
{<br />
Label lblPhone = (Label)(e.Item.FindControl("lblPhone"));<br />
if (lblPhone.Text.Length > 0) <br />
lblPhone.Text = string.Format("{0:(###)###-####}", double.Parse(lblPhone.Text));<br />
}
private void dlCourseDetails_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)<br />
{<br />
Label lblPhoneNumber = (Label)(e.Item.FindControl("lblCoursePhone"));<br />
if (lblPhoneNumber.Text.Length > 0) <br />
lblPhoneNumber.Text = string.Format("{0:(###)###-####}", double.Parse(lblPhoneNumber.Text));<br />
}
Thakns,
CDW
|
|
|
|
|
Typically means you are referencing an object that has not yet been created, was destroyed, is not (or no longer) accessible or is NULL ...
D.
|
|
|
|
|
However, the object is there. When are object bound to the page? Does this occur before the ItemDataBound or after? The binding should occur at the same time for both pages shouldn't it? I'm using the same code on both pages. It works fine on one page and not the other. Would binding work differently on the two pages?
Thanks
CDW
|
|
|
|
|
Unfortunately, I cannot give you that answer ... all I can suggest is to step through the debugger and look at the object you're trying to reference. You should be able to tell if it exists when you reference it.
I have discovered that often times, events are triggered when you least expect it, so you have to check for the existance of the object before you reference it.
D.
|
|
|
|
|
how do i set the install location for dll's in a merge module? the properties window does not contain a location. the dll's are installed in the application folder, when they should be installed in the windows\system32 directory.
|
|
|
|
|
If you are referring to an existing Merge Module (aka, one created for your use), then that information is already stored in the module itself.
In other words, if you're using the MSVCRT merge module in your installer, that merege module already contains the necessary pathing information to place the DLL in the correct location (in this case %windows%\System32).
D.
|
|
|
|
|
i am using the msvcrt merge module from c:\program files\common files\merge modules, but it is being installed in the application folder. any ideas?
|
|
|
|
|
No, since we cannot 'see' how the merge module is/was built. I suggest you just add the DLL to your installer and put it where you need/want it.
D.
|
|
|
|
|
Hi
I want to start programming in C#. I have access to the SharpDevelop tool but not Microsoft Visual Studio or anything like that. I come from a network admin background with very little coding experienece. I'm looking to develop a simple app that will help me with my day to day job, eg reboot server, scan access or check for old files etc... I know I could do this stuff with VB but just interested in learning C#. Taking into account the above does anyone have any books they can recommend?
Thanks
|
|
|
|
|
C# Unleashed is a good book. Covers the basics, Windows Forms, Controls, and Database access (including ADO and internet based development).
Also hit the C# code examples here on Code Project and read anything that's listed as "for a beginner" ... looking at code is one of the best ways to learn.
If you've not already, and I must assume you have, download the 1.1 .NET Framework SDK[^] from Microsoft and review all their C# code examples.
Hope that helps get you started ... Good-luck!
D.
|
|
|
|
|
I won't try to talk anyone out of learning C#. It's a great language and, in my opinion, fun to use.
With that said, however, I would question the appropriateness of it as it pertains to the goals you mentioned. If a GUI is a requirement for the apps you want to build, you can disregard most of this post. Programming C#[^] by Jesse Liberty is a very good book, although it assumes some programming experience.
If you don't need a GUI (ie, you'll run your apps from the command line) and are basically looking for a way to automate some of your job functions, you may be better off learning a scripting language. You can choose from VBScript, JavaScript, Perl and several others to code in. The types of things you mentioned would likely only require a few lines of code to implement.
If you decide scripting is what's right for your needs, Microsoft Windows 2000 Scripting Guide[^] would be a good start. It goes over scripting concepts, individual languages (VBScript, JavaScript, and WSH), as well as some scripting interfaces useful to system administrators (WMI, ADSI).
You can probably get what you want done either way, so it's just a matter of how you want to go abou it. For non-GUI, sys-admin type stuff, I'd choose scripting every time.
Charlie
if(!curlies){ return; }
|
|
|
|
|
VS.NET can generate stubs for members of an interface (by pressing TAB when you have completed typing the interface name against the class definition in the C# Code Editor). I have noticed that it sometimes generates explicit and sometimes implicit interface members. For example, using ICustomTypeDescriptor generates a mixture of implicit and explicit members.
I would like to be able to control how it generates stubs for my own interfaces. Does anyone know whether this can be done ?
Thanks.
Robert.
|
|
|
|
|
I read "Many times many articles",
But still I am struggling to know the exact difference.
Apart from this if I say Object=nothing. What is the impact on Garbage Collector, I want what exactly the garbage collector will take care of this.
|
|
|
|
|
The short answer is that when you set Object=nothing (or Object=null in C#) nothing happens until the garbage collector runs. When the garbage collector runs is non-determinisitic which means that it can't really be predicted.
For more details the following from MSDN should help.
MSDN wrote:
During a collection, the garbage collector will not free an object if it finds one or more references to the object in managed code. However, the garbage collector does not recognize references to an object from unmanaged code, and might free objects that are being used exclusively in unmanaged code unless explicitly prevented from doing so. The KeepAlive method provides a mechanism that prevents the garbage collector from collecting objects that are still in use in unmanaged code.
Other than managed memory allocations, implementations of the garbage collector do not maintain information about resources held by an object, such as file handles or database connections. When a type uses unmanaged resources that must be released before instances of the type are reclaimed, the type can implement a finalizer.
In most cases, finalizers are implemented by overriding the Object.Finalize method; however, types written in C# or C++ implement destructors, which compilers turn into an override of Object.Finalize. In most cases, if an object has a finalizer, the garbage collector calls it prior to freeing the object. However, the garbage collector is not required to call finalizers in all situations. Also, the garbage collector is not required to use a specific thread to finalize objects, or guarantee the order in which finalizers are called for objects that reference each other but are otherwise available for garbage collection.
In scenarios where resources must be released at a specific time, classes can implement the IDisposable interface, which contains the IDisposable.Dispose method that performs resource management and cleanup tasks. Classes that implement Dispose must specify, as part of their class contract, if and when class consumers call the method to clean up the object. The garbage collector does not, by default, call the Dispose method; however, implementations of the Dispose method can call methods in the GC class to customize the finalization behavior of the garbage collector.
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Hi all,
I have done one application in C#, when I load this program in my system as a service( auto) one more application is not running. Once I stop this C# service immediately that program is responding. This is occuring only at the boot of the system. Once this killing of service is done, the problem is not reoccuring. Anybody got some clue why its happening?? I checked the dependencies of this service, there are no dependencies. Still why its happening??
Regards,
Satya Prasad
|
|
|
|
|
I don't completely understand your question, but if you mean that you're trying to run a Windows Forms application from another Windows Service, the service must be marked to interact with the desktop. You can find this property in the Properties sheet for the service in your Services snap-in in the Administrative Tools inside the Control Panel. This is only applicable if your service runs as a local system account. Otherwise, if you run it as a particular user, that user must have a desktop associated with it (it should be created if it doesn't already exist) and must have the "Log on Locally" and "Login as a Service" privileges, which you can configure in the Local Security snap-in.
If this isn't what you're asking about, please elaborate.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi dudes.
I was wondering how to create .dll's in VS.NET? Just curious about it, would be great if someone knew
Thanks!
- Up The Irons, Morten Kristensen
|
|
|
|
|
If you mean you want to export some mothods and propertes you should use CLASS LIBRARY project.
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
thanks.
Serdar YILMAZ
Senior Developer
|
|
|
|
|
Hey...
Like this:
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
- Up The Irons, Morten Kristensen
|
|
|
|
|
this.WindowState = FormWindowState.Minimized;
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
I have a function with a problem as describe in it:
public void Func(Control control)
{
...
...
} I need to know at runtime, whether the control object is actually derived from Form or Button. Any ideas?
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
public void Func(Control c)
{
if (c.GetType().ToString() == "System.Windows.Forms.Form")
{
}
else if (c.GetType().ToString() == "System.Windows.Forms.Button")
{
}
}
|
|
|
|
|