|
Hi,
Just wondering if someone could point me in the right direciton. What I am looking to achieve is to be able to dynamically load a class from an assembly at runtime, to achieve what use to be done using a ProgID/GUID to access a COM object. If someonce could give me a quick overview of the techniques that I should be looking at, that would be great.
Cheers
AJ
|
|
|
|
|
Check out the Activator class. I use Activator.CreateInstanceFrom in some of my code. It seems to work really well.
TF
Tim Friesen
tntfriesen1@hotmail.com
|
|
|
|
|
Extending on what Tim said, the Type is unique to each class, enum, delegate, or struct in an assembly. It contains the namespace and class name, the assembly which contains the type, and a few other pieces of information (including version, culture, and public key token (if signed - which it should be for better applications and versioning control)). This takes the place of GUIDs and ProgIDs.
Besides Activator.CreateInstance , you can have more control over type loading by using the static method Type.GetType . For instance, say in your application's .config file (yourapp.exe.config, which takes the place of the registry which you're not supposed to use in .NET unless necessary) you have a partial type string like "MyNamespace.MyType, MyFirstAssembly" (version information and other stuff can be left out as long as the CLR can resolve "MyFirstAssembly"). If you want to get the type before instantiating it, you can read the value out of the configuration file and call Type.GetType("MyNamespace.MyType, MyFirstAssembly") . That returns a Type which you can use to create an instance of use Reflection to get other information (such as whether or not it implements a particular plug-in interface you require before instantiating, although you could get this by using the is keyword after instantiating, but perhaps instantiating it is pointless to you if it doesn't implement a particular interface).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
My VS.NET installation is really annoying me. I'm using VS.NET 2003 Enterprise Developer and we have created a solution with approx. 30 projects.
VS.NET rebuilds everything every time I select to either build or run the solution - it doesn't matter if I have just changed a single line or added a new project, it always rebuilds everything.
In addition, if I choose build and then run it rebuilds everything two times - one when I choose build and one when I choose run.
Any ideas why VS.NET might be doing this? And better yet - any ideas on how to solve this issue?
Thanks for your help, Mads
|
|
|
|
|
I don't know if this is the answer to your problem but I remember having a similar problem in VS years ago.
It was due to one of the source files having the datestamp set in the future. So VS would look at the times on the source files and on the dll/exe files produced and concluded that since a source file was apparently modified after the exe/dll was produced that it must rebuild it. If that source file is in a project that all others are dependant on then everything will get rebuilt.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
This is actually the way it is supposed to work. From the main menu, the build commands work on every project in the solution. In release builds, any slight change causes the whole thing to recompile because incremental builds are disabled by default.
Here's a tip (I have about 50 projects in my solution, so I do this all the time): Right-click on the project you really want to build and select Build, Rebuild (cleans and builds), or Debug->Start new instance. This will only build the dependencies based on the file modification dates of those projects.
Another tip: To each project that has dependencies on other projects, when you click Add Reference switch to the Projects tab and select the project there. This ensures a proper dependency chain no matter which build configuration your in (Debug, Release, or a custom configuration). This also helps VS.NET resolve which dependencies should be build when you use the first tip above.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Great tip - many thanks, not so annoyed with VS.NET anymore
Mads
|
|
|
|
|
Go to the build project, Configuration Manager option. Unmark the projects that you don't want to build.
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
English is not my native language so, if you find any spelling erros in my posts, please let me know.
|
|
|
|
|
If I do that, the unmarked projects will never be included in the build (not even if they are changed).
Mads
|
|
|
|
|
I’m working as a programmer and make up my living by writing C++ apps with MFC in MS Visual Studio .NET. I have read none about C# but would like to learn it if it could make my day better.
Which are the arguments of changing language??
Pleased for all comments.
and justice for all......
- APe
|
|
|
|
|
If you are doing business applications then C# is better suited. It has easier access to databases, generating web pages, web services and so on. C++ can do these things but it takes more work.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
Note that the two things aren't the same, though. MFC requires one DLL (MFCXX.DLL) to run and uses native DLLs for everything else. C++ just requires whatever DLLs you're calling entry points into.
C# is a managed languages that targets the Common Language Runtime (CLR) and is one of many languages for the .NET Framework which - like the Java Runtime Environment (JRE) - is required to run applications written in that language.
Also, C# - and all languages targeting the CLR - compile to MSIL (Microsoft Intermediate Language, an extension to the standard Intermediate Language), which gets Just-in-time compiled (JIT'd, it can also be ngen'd to pre-JIT an assembly in the Global Assembly Cache) and executed.
So, if you build applications for .NET, the .NET Framework must be installed. Take this as a drawback or bonus. It's called managed code because the CLR manages all memory and bounds-checking.
The best thing you could do to evaluate .NET is to read the .NET Framework SDK documentation which - if you did a full install on the VS.NET studio - is in your help. There's many articles talking about the differences, the class library, and lots of other topics. Like everything, the only way to truly learn (and develop, vs. just writing code) is to read and try it out.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks guys. I’ve noticed I should read the .NET Framework SDK documentation before publishing my question. But it certainly will be more questions later on.
APe
|
|
|
|
|
Hello,
I am trying to create a custom web-service and have it running in the web
server
where the SPS 2003 is installed.It needs to be there cause it wraps
SharePoint DLL's .
However if I put it under
C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\60\TEMPLATE\LAYOUTS\
or
_layouts virtual directory in IIS
I get an error that says :
No http handler was found for request type 'GET'
If I put it in C:\Program Files\Common Files\Microsoft Shared\web server
extensions\60\ISAPI
where the rest of the builtin .asmx files are, then I can't open the
solution from VS.NET at all,
nor can I reference it from another webapplication.
Any suggestions ?
thank you in advance.
Pilgrim
|
|
|
|
|
You can't put a web service in a non-public directory. First, IIS (IUSR_COMPUTERNAME) and ASP.NET (ASPNET) have to be able to access the directory. Second, the directory can't be blocked for access (like the bin directory). Basically, your .asmx file has to go into a publicly-accessible directory and the logic for that file goes into the "bin" subdirectory of your Web Application - just like all other assemblies in ASP.NET. That's where the CLR looks for assemblies (by default) when it loads types.
If the assembly behind the .asmx file needs to access SharePoint DLLs, then make sure those DLLs are in the %PATH% environment variable (i.e., add the directory where those DLLs to your system %PATH% using the Advanced tab of the System control panel).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Does anyone know if its possible or even a good idea to distribute MSDE with your C# applications ??
Any articles ?
|
|
|
|
|
Yes you can. See http://www.microsoft.com/sql/msde/[^] for more information. Basically, if you obtained MSDE through Office Developer, Visual Studio, or several other products, you can redistribute it. The link above and the readme files in the distribution discuss ways of redistributing it using the Windows Installer merge modules, or to bootstrap your application to install an MSI (there are 18 - each one corresponding to one of the 18 instances that can run simultaneously so make upgrading your application easier (just keep using the same named file with each new version of the MSDE).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I am trying to use the "New Project Dialog Box" into my Application .I want it to work like the way it works in VS 7 i.e. when i click the file menu New >New Project i want the New Project Dialog Box to open up.
But the Kinds of Projects /Templates (which i inted to develop later) will be different or specific/modified to the application that i am developing.
Can somebody please advise me/ direct me to a code snippet,so that i can use this object/compnent into my Application.
Rajn
|
|
|
|
|
You can't reuse that dialog because it's in a separate application, so just create your own form and add all the logic yourself. VS.NET searches certain directories for wizard files, reads the information from those and builds a list. Just do the same thing. It's not like it'd be hard to create a similar form for your application.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank You Stewart,I'll follow your guidelines.If i have any problems doing it i'll post the questions on the forum.
Thank You again
Rajnp
|
|
|
|
|
Hello
í want to fill out a html formular on a html webpage using c#
i use a normal webbrowser component to view the site
and then i want to fill out the fields of a fomular by click a button or anything else
could someone help me?
cia buzdaman
|
|
|
|
|
You mean "form"?
So what's the problem? Have you actually tried doing this? It isn't hard, but you're definitely not going to get anyone here to just do it for you.
For simple drag-n-drop "programming", customize your toolbox in VS.NET and add the Microsoft Web Browser control. Drag that on your form. Then you'll have to reference the Microsoft.mshtml.dll assembly in your project and use the WebBrowser.Document property to get a reference to the IHTMLDocument2 interface, which you can then use to access the MSHTML DOM and start assigning values to form elements. There are some examples on MSDN using the web browser control (hint, type "WebBrowser" in the search) and read the documentation for reusing the WebBrowser control at http://msdn.microsoft.com/workshop/browser/prog_browser_node_entry.asp[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
I have a large pool of business objects all referencing one another in various ways.
In the client application I want to do something like
employee.Delete();
Behind the scenes, I want to remove all references to the object allowing it to be garbage collected. I then want to remove the physical representation of the object from persistance. Unless I have missed a scenario, the references to the object can be deleted in two ways
MyParentObject.EmployeeProp = null; or
MyEmployeeList.Remove(employee);
In order to do this, I have to maintain some kind of internal lists of these relationships.
My questions are --
1) Have I missed any other way that an object can be referenced?
2) Isn't there an easier way? Doesn't the GC already have this list somewhere?
Robert Zurer
robert@zurer.com
|
|
|
|
|
Technically, MyEmployeeList.Remove won't remove a reference to the object - it only removes the reference from a list. If a class references that particular object somewhere else, it still won't be GC'd.
One way you can do this - but you must have proper exception handling in place - is to dipose the object (make sure it implements IDisposable somewhere up the class hierarchy and call Dispose() on it). Components and controls are already disposable, as well as many other classes in the .NET BCL.
If another object tries referencing it then, an ObjectDisposedException will be thrown.
Unless you add a collection into which each referencing class must add itself (or, make your object to be referenced a ContextBoundObject and perform the registration yourself since you can intercept / handle even direct method calls and assignments), there is no way to get access to what the CLR knows about your app through managed code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|