|
It should. There could be another permission that's demanded after StrongNameIdentityPermission , but only trying it or examining the IL will tell you that.
Assemblies should always be strongly named, anyway. It's really so easy that there's no reason not to do it. It also helps keep your code secure since the assembly is signed with your private key (so keep it private!).
Look at it this way: if you use a type from another assembly without signing, you're essentially linking against the type MyNamespace.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral ; anyone could replace that and do something malicious. If you sign your assembly (give it a strong name), your type is now MyNamespace.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef . Since only you have that signing key, only you can produce that public key token. This isn't 100% secure (someone could disassemble and change the calling assembly), but nothing always is (native code is better, but not infalable).
As I mentioned earlier, too, it's a good idea to use the same key pair for all your assemblies, or at least for a given solution. It can't be traced back to you like it could if you additionally signed with an X.509 certificate (authenticode; like ActiveX uses), but it is an identifying mark in the way that only you (or your organization - or maybe just the build master) have the private key.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know how to set the cursor while in a 'form' but I want to change the system cursor just before I launch a thread and then change it back to the Arrow when the threaded process completes.
How do I change the system cursor in C#?
cb
|
|
|
|
|
The cursor should not be set for the entire desktop by an application. It's recommended that you set Cursor.Current , which applies to the entire application (Control.Cursor applies only to that window (a control is a window)). There is no reason to set the cursor for the entire desktop, neither. This violates the standard of per-application cursors.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Changing the "system" cursor is unnecessary for a standard application. You should only be concerned about setting UI cues in your application and only your application unless you have very special reasons. Cursor.Current should be more than enough control of the cursor over your application. Set it whatever you want as part of the thread starting set it back to whatever it was before when it is done.
|
|
|
|
|
Thanks, it works like a charm.
cb
|
|
|
|
|
I have a background thead in an Audio program I wrote that scrolls text like a banner. When the text is scrolling I cannot see any TootTips in any other programs. If I stop the Background thread the ToolTips show up again.
Here is the pertinant code:
private delegate void ScrollThreadDelegate();
...
...
ScrollThread = new Thread(new ThreadStart(ScrollThreadFunction));
ScrollThread.IsBackground=true;
ScrollThread.Start();
ScrollThread.Suspend();
...
...
private void ScrollThreadFunction()
{
while(RunScrollThread)
{
if(lbSongInfo.InvokeRequired)
{
this.lbSongInfo.Invoke(new ScrollThreadDelegate(this.ShowScrollText));
}
Thread.Sleep(50);
}
}
private void ShowScrollText()
{
if(lbSongInfo.Location==SongInfoEnd)
lbSongInfo.Location=SongInfoStart;
Point CurPos = new Point(lbSongInfo.Location.X,lbSongInfo.Location.Y);
CurPos.Offset(-1,0);
lbSongInfo.Location=CurPos;
}
private void InitSongInfoLabel()
{
try
{
try
{
ScrollThread.Suspend();
}
catch(Exception){}
string strName = CurTrackItem.SubItems[1].Text;
int strWidth = (int)grfx.MeasureString(strName, lbSongInfo.Font).Width + 5;
SongInfoStart=SongInfoEnd=new Point(0,0);
SongInfoStart.Offset(pnSongInfo.Width,0);
SongInfoEnd.Offset(strWidth*-1,0);
lbSongInfo.Location=SongInfoStart;
lbSongInfo.Width=strWidth;
lbSongInfo.Height=pnSongInfo.Height;
lbSongInfo.Text=strName;
lbSongInfo.TextAlign = ContentAlignment.MiddleCenter;
}
catch(Exception Err)
{
MessageBox.Show("InitSongInfoLabel Exception : "+Err.Message);
}
finally
{
ScrollThread.Resume();
}
}
Can anyone see what might cause this issue?
|
|
|
|
|
Guinness4Strength wrote:
int strWidth = (int)grfx.MeasureString(strName, lbSongInfo.Font).Width + 5;
Where do u get that Graphics instance from? Looks like the cultprit. Also you should be invoking rather directly calling methods on a control from another thread.
top secret xacc-ide 0.0.1
|
|
|
|
|
1. I call CreateGraphics() in the FormLoad event handler.
2. I am using Delegates and Invokes. Take a look at the ScrollThreadFunction()
|
|
|
|
|
Guinness4Strength wrote:
1. I call CreateGraphics() in the FormLoad event handler.
Thats no good, you can only use the Graphics object supplied by OnPaint (and friends).
Guinness4Strength wrote:
2. I am using Delegates and Invokes. Take a look at the ScrollThreadFunction()
A delegate is just a function pointer the way you use it in your example. You need to do Control.Invoke and use the ISyncronizedInvoke interface implementation.
top secret xacc-ide 0.0.1
|
|
|
|
|
1. If using CreateGraphics() is not allowed, why is it there ?
the MSDN exmaple shows it's use inside a function that does not receive any PaintEventArgs:
private void AutoSizeControl(Control control, int textPadding)
{
Graphics g = control.CreateGraphics();
Size preferredSize = g.MeasureString(
control.Text, control.Font).ToSize();
control.ClientSize = new Size(
preferredSize.Width + (textPadding * 2),
preferredSize.Height+(textPadding * 2) );
g.Dispose();
}
2: I AM calling Control.Invoke() and implementing ISyncronizedInvoke interface
<pre?
if(lbsonginfo.invokerequired)
{
this.lbsonginfo.invoke(new="" scrollthreaddelegate="" his.showscrolltext));
}
<="" pre="">
|
|
|
|
|
I've just spent the last 3 hours trying to debug this one without luck.
my simplified server code:
static void Main()
{
RemotingServices.Marshal(myObj, "myObj.rem");
while(true)
{
string command = Console.ReadLine();
if(command == "test") Console.WriteLine("hello");
}
}
my simplified client code:
IMyObj theServerObj = RemotingServices.Connect(typeof(IMyObj), ...);
theServerObj.DoSomething();
When I run the client and server, the client connects to the server's remote object, then calls the DoSomething method, no problems at all. If I restart the client app while still running the same server instance and run the code again, the client hangs on the .DoSomething() line. Visual Studio's debugger tells me the server is waiting for input on the Console.ReadLine method. And sure enough, if I enter "test" into the console, it writes "hello" and the client is then able to connect. To make matters more mysterious, any attempts to connect by running a client a 3rd, 4th, etc. time works without problem.
So to summarize, the code works without problem the first time a client connects. IF the client is restarted, it doesn't connect until the server gets input. If the client is restarted again (and any consecutive attempts hereafter), all works fine again.
I do use some locks in my code but from what I can tell all locks are released after the first connects; everything should still work. Anyone have any suggestions?
Judah Himango
|
|
|
|
|
Are you calling RemotingServices.Disconnect after calling DoSomething ? If not, the object may hang around on the server channel.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Call disconnect on the server objects? Na, don't want to do that because I want the client to connect to that singleton, I don't want to publish a new IMyObj from the server each time.
Judah Himango
|
|
|
|
|
No, on the client (after connecting and calling DoSomething ). Maybe I'm not understanding your code snippets, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, yes, I am disconnecting all client-published objects (which I didn't mention in the code snippet). I cannot disconnect server proxy objects on the client side of course.
This is one of the strangest problems I've ever seen, given it occurs only during certain instances of the client application. Hard to debug too with multiple threads running across application and machine boundaries. :-p
Judah Himango
|
|
|
|
|
Without more hints (or code) I have no idea how the objects are configured or even guess how they behave during their life time. Just dropping an object into a thread and assuming it will be "thread safe" is dangerous. Just dropping an object into the remoting framework and assuming it will be "multiple client safe" is equally as dangerous.
|
|
|
|
|
You're right. It is bizaare. I think you will agree that the key piece of information is that the reconnect fails only when the main thread is blocked on the first call to Console.ReadLine. What would the Console class be doing that would have any impact on your remoting object anyway? Is DoSomething using the Console class in any way? Can you whip up the smallest program that demonstrates the problem and post the code? Maybe in the process of working on that you'll discover the problem, but if not then you'll have something complete that all of us can take a look at.
|
|
|
|
|
Is there any easy way to convert .rc (C++ resource) files to .resx (C# resource) files? I have a C++ project which I'm converting to C# and don't want to have to write my own utility to convert the old resource files over.
BRCKCC
|
|
|
|
|
Hi,
Where can I find a sample code for passing array or VARIANT from ATL COM control to C# .NET?
Thanks,
Alex
|
|
|
|
|
Search CodeProject.
The important thing is developing your .NET code correctly. Use the MarshalAsAttribute with the appropriate UnmanagedType enumeration member. For an object[] array, you can use a myriad of choices but commonly - if you're passing an array of variants - you'll either use UnmanagedType.LPArray or UnmanagedType.SafeArray . A SAFEARRAY in unmanaged code stores information for each elements (what VARTYPE it is).
Read about the MarshalAsAttribute in the .NET Framework SDK to start. You should also read Interoperating with Unmanaged Code[^] in the .NET Framework SDK, specifically Marshalling Data with COM Interop[^]. This presents a lot of information you must understand, as well as some examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I'm trying to pass a custom object to a web service as a web method parameter. For this, I had to modify the References.cs file and delete the simplified version of the class, so I can pass directly my objects.
The problem is that when I check the object in the web service, the collection that includes is empty. Do you know what can be happening?
I don`t know how to solve this.
|
|
|
|
|
Diego F. wrote:
For this, I had to modify the References.cs file and delete the simplified version of the class, so I can pass directly my objects.
You will have to add some XmlSerializer attributes for that to work I think. See how the other members are handled, and be warned, never edit generated code.
top secret xacc-ide 0.0.1
|
|
|
|
|
I tried using object arrays, but the only way I could make it work was using a Dataset. I added a method that returns a DataSet with the attributes mapped, and it works without modifying the References.cs file.
I think I'll leave now, because it is taking so long.
|
|
|
|
|
What do I have to do, in order to hand over a parameter to a function, which was compiled before by (ICodeCompiler CreateCompiler())?
I know, that I need the „InvokeMember“, which only permits the type Object, but I need the type HttpContext.
What do I do wrong, or is there something I forgot, or is there another way?
Yours,
Patrick
|
|
|
|
|
Every type in .NET derives from System.Object , so when a parameter, properties, etc. takes an Object , you can pass anything (including value types like structs, the primatives, etc., but that performs boxing and unboxing which is a performance penalty, mind you). This is VERY important to understand.
This means that every type inherits the members of Object and may override some (like ToString , GetHashCode , and Equals ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|