473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Windows 2003 SP1 and specified cast is not valid

Hello,

I had an ASP.NET application running on Windows 2003 machine and it was
all working fine. I upgraded the machine to Windows 2003 SP1 and now my
application is failing with "Specified cast is not valid" exception.
Here is the code snippet where the error comes from.

Object o=System.Activator.CreateInstance(t);
IMyInterface p = (IMyInterface)o;

I create an instance of type t and attempt to cast it to interface
IMyInterface. This was working fine till the moment I upgraded Windows
2003 SP1.

My belief is Window 2003 SP1 would have upgraded .NET framework 1.1 as
well and there must be some behavioral change in .NET framework SP1.

I found the following KB on Microsoft site which showed the similar
symptoms where Biztalk Server 2004 failed due to same reason after
applying .NET framework SP1.

http://support.microsoft.com/default...B;EN-US;875540

Although the KB talks about the hotfix for Biztalk server, it doesn't
talk about the underlying reason for this breaking after applying .NET
framework SP1.

Can anybody shade some light on this?

Thanks.
-Prasad

Nov 19 '05 #1
6 1630
Why not simply debug, add a breakpoint at that 2nd line, and add a watch to
o, it should tell you what type it really is. It's possible that the
upgrade to 1.1 is making CreateInstance load to wrong type/version/assembly
or something like that...
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<pd****@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hello,

I had an ASP.NET application running on Windows 2003 machine and it was
all working fine. I upgraded the machine to Windows 2003 SP1 and now my
application is failing with "Specified cast is not valid" exception.
Here is the code snippet where the error comes from.

Object o=System.Activator.CreateInstance(t);
IMyInterface p = (IMyInterface)o;

I create an instance of type t and attempt to cast it to interface
IMyInterface. This was working fine till the moment I upgraded Windows
2003 SP1.

My belief is Window 2003 SP1 would have upgraded .NET framework 1.1 as
well and there must be some behavioral change in .NET framework SP1.

I found the following KB on Microsoft site which showed the similar
symptoms where Biztalk Server 2004 failed due to same reason after
applying .NET framework SP1.

http://support.microsoft.com/default...B;EN-US;875540

Although the KB talks about the hotfix for Biztalk server, it doesn't
talk about the underlying reason for this breaking after applying .NET
framework SP1.

Can anybody shade some light on this?

Thanks.
-Prasad

Nov 19 '05 #2
Hello,

I added some logging to my code

Object o=System.Activator.CreateInstance(t);
IMyInterface p = (IMyInterface)o;
Type t1=typeof(IMyInterface);
Type t2=o.GetType().GetInterface("IMyInterface", true);
log.Info("t1.AssemblyQualifiedName=" + t1.Assembly.CodeBase);
log.Info("t2.AssemblyQualifiedName=" + t2.Assembly.CodeBase);

It prints two different paths for the assembly (one coming from GAC and
one from the directory from where the application is loaded. Hence, its
not allowing for the cast operation.

NOTE: I tried the same application on other system not having Windows
2003 SP1 and the above code prints same paths for the assembly pointing
to location in GAC.

There must be some behavioural change in .NET framework 1.1 and .NET
framework 1.1 with SP1.

Any thoughts?

-Prasad

Nov 19 '05 #3
This thread is a little old in my head, but woudln't the output of your code
largely depend on how you got your variable t ?

I went through:
http://support.microsoft.com/?kbid=867460 which lists the SP1 fixes, and
didn't see anything relevant.

I can't offer much more help. You might want to consider a new post with
the additional information you now have so that someone else might be able
to help..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<pd****@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I added some logging to my code

Object o=System.Activator.CreateInstance(t);
IMyInterface p = (IMyInterface)o;
Type t1=typeof(IMyInterface);
Type t2=o.GetType().GetInterface("IMyInterface", true);
log.Info("t1.AssemblyQualifiedName=" + t1.Assembly.CodeBase);
log.Info("t2.AssemblyQualifiedName=" + t2.Assembly.CodeBase);

It prints two different paths for the assembly (one coming from GAC and
one from the directory from where the application is loaded. Hence, its
not allowing for the cast operation.

NOTE: I tried the same application on other system not having Windows
2003 SP1 and the above code prints same paths for the assembly pointing
to location in GAC.

There must be some behavioural change in .NET framework 1.1 and .NET
framework 1.1 with SP1.

Any thoughts?

-Prasad

Nov 19 '05 #4
Hello,

Type t is created is created as follows.

1. IMyInterface is defined in an assembly say myinterface.dll
2. myinterface.dll is placed in GAC.
3. IMyInterface is implemented in as assembly say myobject.dll
4. My application dynamically loads myobject.dll using
AppDomain.CurrentDomain.Load("myobject");
5. Then it enumerates the types in assembly and finds the one that
implements IMyInterface. This is "t" that I refer to in the code
snippet.

There is also a copy of myinterface.dll kept in application root
directory. If I remove this copy, things work fine. But, I want to know
if there is a way to get it working even if there is a local copy in
application root directory.

NOTE: This was all working fine irrespective of whether there is local
copy in application root directory or not. It broken only after I
upgraded to Windows 2003 SP1 which I presume installs .NET framework
1.1 SP1 also.

Thanks.
-Prasad

Nov 19 '05 #5
Prasad:
I've never used AppDomain.CurrentDomain.Load() to get a type. I normally
use Type.GetType() and I know when you use Type.GetType("xxx") and you want
to reference something in the GAC, you need to use the full assembly name,
including culture, version and publictoken. In other words, if I did

Type t = Type.GetType("myobject"); it probably wouldn't work, but if I
did
Type t = Type.GetType("ClassName, myObject, Version=1.0.00000.0,
Culture=neutral, PublicKeyToken=asdaso098098"); it probably would work.

Perhaps you need to do the same thing?

If you go into C:\WINDOWS\assembly you'll see a list of assemblies in the
GAC and you can get their Version, Culture and PublicKeyToken from the list
:)

I might be on the totally wrong track, but hope this is helpful,

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

<pd****@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello,

Type t is created is created as follows.

1. IMyInterface is defined in an assembly say myinterface.dll
2. myinterface.dll is placed in GAC.
3. IMyInterface is implemented in as assembly say myobject.dll
4. My application dynamically loads myobject.dll using
AppDomain.CurrentDomain.Load("myobject");
5. Then it enumerates the types in assembly and finds the one that
implements IMyInterface. This is "t" that I refer to in the code
snippet.

There is also a copy of myinterface.dll kept in application root
directory. If I remove this copy, things work fine. But, I want to know
if there is a way to get it working even if there is a local copy in
application root directory.

NOTE: This was all working fine irrespective of whether there is local
copy in application root directory or not. It broken only after I
upgraded to Windows 2003 SP1 which I presume installs .NET framework
1.1 SP1 also.

Thanks.
-Prasad

Nov 19 '05 #6
Hello,

Yes I agree that if I specify full assembly name, it will work.

The thing that concerns me most and I really want to know about is,
what is changed in .NET framework 1.1 SP1 that changes the behaviour.

If you look at
http://support.microsoft.com/default...B;EN-US;875540, .NET
framework 1.1 SP1 has clearly broken some backward compatibility for
Biztalk and Microsoft has to release a patch for Biztalk to address
that. Although, KB talks about the patch and says that its happens
after applying .NET framework 1.1 SP1, it doesn't say anything about
what changed in SP1 that lead to releasing a patch for Biztalk.

Thanks.
-Prasad

Nov 19 '05 #7

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

Similar topics

4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
2
by: Kashiefah | last post by:
Hi, I keep on receiving this error when I click on the edit email link from the datagrid:Specified cast is not valid. Description: An unhandled exception occurred during the execution of the...
2
by: thithi | last post by:
Server Error in '/Assignment' Application. -------------------------------------------------------------------------------- Specified cast is not valid. Description: An unhandled exception...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.