|
Nice, Nish. +5
So this has something to do with the inferrable type. Why does adding the T:class modifier help...said another way, what are the non-convertable types that it's griping about?
Cheers.
|
|
|
|
|
TheyCallMeMrJames wrote: Why does adding the T:class modifier help...said another way, what are the non-convertable types that it's griping about?
Value types. The compiler can't know in advance that T won't be a value type.
|
|
|
|
|
|
Awesome! Works perfectly! I was trying where T : Object but was getting a compiler error.
Thank you!
|
|
|
|
|
Hey All,
I have a problem with dynamically loading and referenced assembly at run time. The issue is that i am coding a 3rd party app for a larger application that is constantly getting patched and upgraded. Every time a new patch or upgrade comes out i need to recompile and redistribute the app too all the clients. Now nothing really ever changes in the referenced assembly aside from version number which is causing me to have to remove the reference and add it again. I don't even have to change code, just update the reference.
I know i can load this specific assembly when the reference isn’t found by attaching to the AssemblyResolve event; however this is where I’m having problems. I’m not exactly sure how i should implement this. All the documentation i can find from MS isn’t very helpful, as per usual.
Really the end goal is to have it load this referenced assembly when it is called at run time. The referenced assemblies path will change from machine to machine so it needs to fully dynamic, i can work out finding the proper assembly to load i just need some insight on the best way to implement this.
Also another quick question ... if i reference say v1.2 and then dynamically load v3.5 is the framework going to freak out about the version numbers or just accept that this is the assembly i want to load.
TIA
Don't comment your code - it was hard to write, it should be hard to read!
|
|
|
|
|
How are you loading them dynamically? You don't need to specify the version (assuming you are using Reflection) and instead can just load from a file path.
|
|
|
|
|
First, thanks for the reply.
Nishant Sivakumar wrote: How are you loading them dynamically?
Assembly.LoadFrom([path_to_assembly])
I will need to find the path to the assembly myself, which is not a problem. The problem is the proper implementation. I want to have a reference at design time, just set Copy To Local to false, and then at runtime actually go out and find the proper assembly on the client machine.
Nishant Sivakumar wrote: You don't need to specify the version (assuming you are using Reflection) and instead can just load from a file path.
Just what i thought, thanks for confirming this.
Thanks again for the reply
Don't comment your code - it was hard to write, it should be hard to read!
|
|
|
|
|
Register the Assembly Resolve event before starting your applications message pump, or in the case of an ASP.NET application in the Application_Start event. Other than that, post a specific issue. I have never had a problem using Assembly resolve; it is fairly straight forward. Here is a copy and paste from another project with some namespaces removed.
using System;
using System.Data;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace _Website {
public class AssemblyResolver {
private bool mLoading = false;
public AssemblyResolver(AppDomain appDomain) {
appDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
}
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) {
Assembly result = null;
if(!mLoading) {
try {
mLoading = true;
IServiceBroker broker = ServiceRequests.CommonRequests.GetBroker();
byte[] assembly = broker.ResolveAssembly();
result = Assembly.Load(assembly);
}
finally {
mLoading = false;
}
}
return result;
}
}
}
|
|
|
|
|
Fantastic, great implementation and pretty much exactly what i was looking for.
Another thing, i am inheriting from classes inside the referenced assembly, is there a way to implement this for inheritence inside a class library?
I tried throwing it inside the constructor, but it fails because when it goes to create the class it cant find the reference. I guess my question would be; is there a way to implement this globably for a class library?
Thx for the reply
Don't comment your code - it was hard to write, it should be hard to read!
|
|
|
|
|
Hello,
i want to communicate between a client/server application with HttpWebRequest an HttpWebResponse. My problem is, that i have a server farm. I want to have sessions and want to be able to send and receive informations.
The problem is now, that i can't really work like a web-Server. A request and i deliver a response. I need to talk on one connection in a duplex way. So is it possible to create a HttpWebRequest and to send informations in it, receive some informations and use the same Request(Connection) for sending another Informations?
Thank you
|
|
|
|
|
Hello SoftwareJaeger,
The short answer is NO, HttpWebRequest/Response is just that a single request and response. You can constantly open, close and re-use them all you like but you are not going to get the bi-directional (or duplex) communication you are looking for.
What you need is to actually open TCP or UDP sockets and then send all your calls from there. Really a very basic example would be a chat client (i.e. Windows Live Messenger) which implements the type of functionality you want. There is a great little article here on CP that will walk you through creating a chat client with UDP sockets here[^] that will illustrate the principals of what it is that you need to do.
Don't comment your code - it was hard to write, it should be hard to read!
|
|
|
|
|
A little back story to Adam's response:
HTTP is a stateless protocol. You fire, and you're not necessarily guaranteed a response. In some web farms sessions are maintained across servers, but in others, the sessions are load balanced. You should be able to rely on session data, but it is still not proper stateful communication.
The client makes a request (breaking it down, even, in multi-part scenarios).
The server fulfills the request (by returning a status code and possibly payload).
That is the end of com.
As Adam suggested, you'll need to drop to a different protocol/level to achieve what you're looking for and maintain the open connection.
Cheers.
|
|
|
|
|
Hi,
I am working on an application which needs to monitor the system states (power states) and display modes.
I would like to know if there is a way to register my application for power states (s0 -s5) change events? I mean if the system power state transitions from s0 - s1 etc.
Also how would we know if the display mode is changed from lets say dual display, cloned display etc?
I am trying to get these information on net but in vain
Any help is appreciated.
Regards,
HalliHaida
|
|
|
|
|
Sadly I cannot give you an accurate answer. I really don't know but when I have to do something similar to what you are posting, I always have a look at WMI Classes. Maybe you will find something useful there.
|
|
|
|
|
Hi,
some system-oriented events are available through the SystemEvents class; however I doubt you'll find exactly what you want there.
The alternative is by having a Form, overriding its WndProc, and looking for the right Windows messages, such as WM_POWERBROADCAST[^]. I don't know what message is sent when the dual monitor setup changes, I trust there is one though.
|
|
|
|
|
Hi! I have this code:
class Program
{
static void Main(string[] args)
{
List<Bar1> bar1List = new List<Bar1>();
bar1List.Add(new Bar1());
bar1List.Add(new Bar1());
bar1List.Add(new Bar1());
List<Bar2> bar2List = new List<Bar2>();
bar2List.Add(new Bar2());
bar2List.Add(new Bar2());
bar2List.Add(new Bar2());
List<Foo> fooList = new List<Foo>();
}
}
abstract class Foo
{
public string type;
public Foo(string type)
{
this.type = type;
}
}
class Bar1 : Foo
{
public Bar1() : base("Bar1")
{
}
}
class Bar2 : Foo
{
public Bar2() : base("Bar2")
{
}
}
Notice lists "bar1List" and "bar2List". I would like to add all those elements of those lists into the "fooList".
I know I can use .ConvertAll<Foo>()-method from "bar1List" and "bar2List" with a appropriate delegate converter method, but I would like to know if there are any better solutions?
|
|
|
|
|
List<Foo> bar1List = new List<Foo>();
bar1List.Add(new Bar1());
bar1List.Add(new Bar1());
bar1List.Add(new Bar1());
List<Foo> bar2List = new List<Foo>();
bar2List.Add(new Bar2());
bar2List.Add(new Bar2());
bar2List.Add(new Bar2());
List<Foo> fooList = new List<Foo>();
fooList.AddRange(bar1List);
fooList.AddRange(bar2List);
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Just what I needed! Thanks!
|
|
|
|
|
You're welcome!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi
I am trying to develop a program in which I have to scan an image and pick out some stuff from it.
Assume that I have the image (in jpg).
The image contains Multiple Choice Questions with answers (marked with a black dot next to it).
Now I need to read the image and calculate the total right answers.
I am planning to do this in C#.net.
I have read Christian Graus articles for image processing but didn't find them relevant to my program.
Can some help me about how i should begin?
|
|
|
|
|
Message Closed
modified 23-Nov-14 5:52am.
|
|
|
|
|
Yes, thats how i am trying. But its too much of labor!!
how can i detect a dot (for answer) or a number (for question number) in the image?
|
|
|
|
|
This is a relatively complex task, even though it doesn't seem like it.
1st you need an algorithm to find the answers. If you can make the questions on the exam one per page or a fixed size you'll reduce the complexity, as would fixing the position of the answer grid. This helps with finding the answers in the scans by reducing the area they appear in. Another solution would be to print some solid bars on the side of the page and find those, they should be level with the answer. If the bars are skewed (e.g. the scan is skewed) you should be able to work out the rotation from there. If the bars are on the wrong side the scan is upside down which could happen. You can then straighten the image and re-find the answer
Once you know where the answer grid is A neural network would be easy to train for yes/no ABCDE type answers if you are so inclined(especially if the number of choices is fixed, the NNW takes the answer squares area pixels as input, and categorises to a number of outputs each representing and answer. That said, an algorithm might just be easier, say identifying the squares and finding which, in order has the most black pixels.
The first step will probably need the scan colour depth reduced to 1-bit to make, this makes processing the image easier, and requires less memory if processing lots of scans. You'll also need a
|
|
|
|
|
OK Keith and OriginalGriff have given a huge idea. Thanks a lot guys.
I will start in that direction. I hope I get the right to modify the question paper. If thats possible, then the project seem feasible for a single person.
Also Erik, could you please explain what module you developed?
|
|
|
|
|
Keith is correct, but there is another way which can make locating the answers easier, (if you have control of the paper). Put registration marks in two (or preferably four) of the corners. If you make these a specific colour so they are easy to find, than locate the marks and use them to find the answers since you know the relative positions.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|