473,657 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem

Hi there,

When I run the following on my app's primary thread:

System.Type.Get Type("System.Wi ndows.Forms.For m")

It works as expected. If I then launch a thread via the "BackgroundWork er"
class immediately after the above call, and invoke the above again as soon
as the thread starts, it now returns null instead. Can anyone explain this.
Thanks.
Dec 1 '06 #1
19 1587
Larry Smith wrote:
Hi there,

When I run the following on my app's primary thread:

System.Type.Get Type("System.Wi ndows.Forms.For m")

It works as expected. If I then launch a thread via the "BackgroundWork er"
class immediately after the above call, and invoke the above again as soon
as the thread starts, it now returns null instead. Can anyone explain
this. Thanks.
Change the call to System.Type.Get Type("System.Wi ndows.Forms.For m", true);

This change will cause it to throw an exception if it can't determine the
type. The details in the exception might give you an indication as to what
is going wrong.
--
Tom Porterfield

Dec 1 '06 #2

"Tom Porterfield" <tp******@mvps. orgwrote in message
news:u0******** *****@TK2MSFTNG P02.phx.gbl...
Larry Smith wrote:
>Hi there,

When I run the following on my app's primary thread:

System.Type.Ge tType("System.W indows.Forms.Fo rm")

It works as expected. If I then launch a thread via the
"BackgroundWor ker"
class immediately after the above call, and invoke the above again as
soon
as the thread starts, it now returns null instead. Can anyone explain
this. Thanks.

Change the call to System.Type.Get Type("System.Wi ndows.Forms.For m", true);

This change will cause it to throw an exception if it can't determine the
type. The details in the exception might give you an indication as to
what is going wrong.
Thanks very much. It's returning "System.TypeLoa dException". Docs state that
the "... common language runtime cannot find the assembly or the type within
the assembly, or cannot load the type". I see no obvious reason for this
although I do have a form going on the primary thread (why should this
matter though). Can you or anyone else comment? Thanks.
Dec 1 '06 #3
Larry Smith <no_spam@_nospa m.comwrote:
When I run the following on my app's primary thread:

System.Type.Get Type("System.Wi ndows.Forms.For m")

It works as expected. If I then launch a thread via the "BackgroundWork er"
class immediately after the above call, and invoke the above again as soon
as the thread starts, it now returns null instead. Can anyone explain this.
I would expect the above call to return null in either thread,
personally - Type.GetType(st ring) only looks in the currently executing
assembly and mscorlib unless the assembly details are specified.

In the real code, are you doing this with a string variable instead of
the hard-coded type name? If you only ever want to find the above type,
just use typeof(System.W indows.Forms.Fo rm).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 1 '06 #4
I would expect the above call to return null in either thread,
personally - Type.GetType(st ring) only looks in the currently executing
assembly and mscorlib unless the assembly details are specified.
It does work on the main thread but fails on the worker thread as noted.
In the real code, are you doing this with a string variable instead of
the hard-coded type name? If you only ever want to find the above type,
just use typeof(System.W indows.Forms.Fo rm).
No. I'm actually reading the type on-the-fly from a file. I only have the
fully-qualfied path name to work with as a string
("FullNamespace .ClassName"). I need to generate the assembly-qualified name
from this however. It will always be a native .NET type. Can you steer me in
the right direction. Thanks very much.
Dec 2 '06 #5
Larry Smith <no_spam@_nospa m.comwrote:
I would expect the above call to return null in either thread,
personally - Type.GetType(st ring) only looks in the currently executing
assembly and mscorlib unless the assembly details are specified.

It does work on the main thread but fails on the worker thread as noted.
That sounds very odd, and I can't reproduce it. Can you post a short
but complete program which demonstrates it working in the main thread?
In the real code, are you doing this with a string variable instead of
the hard-coded type name? If you only ever want to find the above type,
just use typeof(System.W indows.Forms.Fo rm).

No. I'm actually reading the type on-the-fly from a file. I only have the
fully-qualfied path name to work with as a string
("FullNamespace .ClassName"). I need to generate the assembly-qualified name
from this however. It will always be a native .NET type. Can you steer me in
the right direction. Thanks very much.
Well, either the file needs to specify the assembly as well, or if you
have a list of assemblies to check for all types, you could just keep
Assembly references, and call Assembly.GetTyp e on each of them until
you find a match.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 2 '06 #6
Hello Larry,

Have u tried to specify fully qualified name of your assembly?

BTW, have u loaded it before calling GetType?
>>When I run the following on my app's primary thread:
System.Type.G etType("System. Windows.Forms.F orm")

It works as expected. If I then launch a thread via the
"BackgroundWo rker"
class immediately after the above call, and invoke the above again
as
soon
as the thread starts, it now returns null instead. Can anyone
LSThanks very much. It's returning "System.TypeLoa dException". Docs
LSstate that the "... common language runtime cannot find the assembly
LSor the type within the assembly, or cannot load the type". I see no

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 2 '06 #7

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
Larry Smith <no_spam@_nospa m.comwrote:
I would expect the above call to return null in either thread,
personally - Type.GetType(st ring) only looks in the currently executing
assembly and mscorlib unless the assembly details are specified.

It does work on the main thread but fails on the worker thread as noted.

That sounds very odd, and I can't reproduce it. Can you post a short
but complete program which demonstrates it working in the main thread?
In the real code, are you doing this with a string variable instead of
the hard-coded type name? If you only ever want to find the above type,
just use typeof(System.W indows.Forms.Fo rm).

No. I'm actually reading the type on-the-fly from a file. I only have the
fully-qualfied path name to work with as a string
("FullNamespac e.ClassName"). I need to generate the assembly-qualified
name
from this however. It will always be a native .NET type. Can you steer me
in
the right direction. Thanks very much.

Well, either the file needs to specify the assembly as well, or if you
have a list of assemblies to check for all types, you could just keep
Assembly references, and call Assembly.GetTyp e on each of them until
you find a match.
Actually, the "file" I'm reading is source code. I'm reading ".cs" files in
a loaded solution (using an AddIn), extracting the name of a class in the
file (including its namespace), and it's this class whose assembly-qualified
name I want to find (its base class actually). The IDE itself is able to do
this without issue (long story) so presumably I should be able to do it as
well (assuming it's not relying on proprietary functions). I'll see if I can
condense this to a simple working example and post it as soon as I can
(perhaps a day or two). Thanks for your help ...
Dec 2 '06 #8
Hello Larry,
>
Have u tried to specify fully qualified name of your assembly?
All I have to work with is the full namespace and class name. Again, passing
this to "GetType()" works on the main thread (returning the
assembly-qualified name) but not on a worker thread.
BTW, have u loaded it before calling GetType?
I'm not sure what I really need to do. I have a form going on the main
thread so the assembly is obviously loaded, i.e., I can get the
fully-qualifed assembly name by passing "System.Windows .Forms.Form" to
"GetType()" . Doing this on a worker thread then fails. Ok, based on what Jon
said I'm guessing that this works because the forms assembly is somehow
bound to the main thread but not to the worker thread. Is this right? In any
case, given only "System.Windows .Forms.Form" to work with or any other
native .NET type for that matter, how can you get the fully-qualifed
assembly name even if the assembly isn't loaded. You don't know which
assembly contains it and you only have this string to work with. Thanks for
your help.
Dec 2 '06 #9
Larry Smith <no_spam@_nospa m.comwrote:
Well, either the file needs to specify the assembly as well, or if you
have a list of assemblies to check for all types, you could just keep
Assembly references, and call Assembly.GetTyp e on each of them until
you find a match.

Actually, the "file" I'm reading is source code. I'm reading ".cs" files in
a loaded solution (using an AddIn), extracting the name of a class in the
file (including its namespace), and it's this class whose assembly-qualified
name I want to find (its base class actually). The IDE itself is able to do
this without issue (long story) so presumably I should be able to do it as
well (assuming it's not relying on proprietary functions). I'll see if I can
condense this to a simple working example and post it as soon as I can
(perhaps a day or two). Thanks for your help ...
The IDE has a list of referenced assemblies, so can easily ask each of
those assemblies whether or not it contains a type of the given name.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2305
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece of code in question always crashes in an STL operation such as a vector.push_back, but the location of the crash changes as I change how various parts are handled in memory, i.e., make some things dynamically allocated instead of new'd. I know...
2
1962
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
25
3717
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
2
1780
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions to perform some calculations. After some number of iterations, randomly, I'll get an uncaught NullValueException error on one of these calls, as if the class name is being treated as an object reference and is null. Here is some psuedo-code to...
1
3761
by: Sam Kong | last post by:
Hello! Recently I had a strange problem with Visual C# 2005 beta 1. When I ran(F5 key) a program, <#if DEBUG> statement was not working. It ran as RELEASE mode. So I had to manually define DEBUG to make #if DEBUG work. When I first started the project, this problem didn't exist. The problem started to exist in the middle of doing the project. Today, I decided to figure out what went wrong.
8
6699
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and contains a few controls anchored to the sides of the form. "frmChild" inherits from "frmBase"... and the controls appear on the inherited form as expected. However things start going wrong when I place addition controls on the "frmChild" form. When I...
11
2588
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
12
2263
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
8
5301
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
5
2428
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7 and its clones I encounter a strange problem where I can hear clicking sound non-stop (like the page is being reloaded non- stop), whereas the page is not reloading.
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.