473,513 Members | 6,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Unable to cast object of type 'System.Byte[]' to type 'System.IO.Stream'.

6 New Member
I uploaded music file in SQl DB in a image dataype
.But when i try to reterive it,It doesn't play.

It gives the following type casting error on runtime

"Unable to cast object of type 'System.Byte[]' to type 'System.IO.Stream'.

I used the following code to play musicfile


while (myReader.Read())
{
Response.ContentType = (string)myReader["Img_Type"];

System.Media.SoundPlayer d = new System.Media.SoundPlayer();
d.Stream = (Stream)myReader["Img_File"];
d.Play();


Can any one help for this?
Oct 7 '07 #1
2 10783
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
I uploaded music file in SQl DB in a image dataype
.But when i try to reterive it,It doesn't play.

It gives the following type casting error on runtime

"Unable to cast object of type 'System.Byte[]' to type 'System.IO.Stream'.

I used the following code to play musicfile


while (myReader.Read())
{
Response.ContentType = (string)myReader["Img_Type"];

System.Media.SoundPlayer d = new System.Media.SoundPlayer();
d.Stream = (Stream)myReader["Img_File"];
d.Play();


Can any one help for this?
Expand|Select|Wrap|Line Numbers
  1. d.Stream = new MemoryStream(byteArray);
cheers
Oct 7 '07 #2
Plater
7,872 Recognized Expert Expert
Yes, Shashi is right, you will need to convert the byte[] to a stream object correctly.
You should pay attention to your error messages. They're usually very helpful and quite clear.
Oct 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
7359
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
4
3814
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
0
11212
by: Aryeh Holzer | last post by:
Hi, I've been trying to use the weather webservice available from the National Weather Service (NWS), at http://www.nws.noaa.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML. wsdl without success. Here's...
0
2400
by: quocvuong2005 | last post by:
Hi all ! I have a webservice that contains a Helloworld() method (This return a string type ) and a asp.net application . I call Helloworld method from webservice , it works fine . but when i call...
0
2527
by: quocvuong2005 | last post by:
Hi all ! I have a webservice that contains a Helloworld() method (This return a string type ) and a asp.net application . I call Helloworld method from webservice , it works fine . but when i call...
4
2447
by: JackBlack | last post by:
Hi, all! Need a little help tracking down a runtime error problem. I'm getting this error: "Unable to cast object of type 'myStruct' to type 'myStruct'... but the two types are identical! I...
1
2932
by: epatrick | last post by:
I have a series of custom controls developed under ASP.NET 1.1, and I've successfully migrated to ASP.NET 2.0. I have also developed a custom class dervied from System.Web.UI.Page, called...
10
7516
by: R2d2Rabeau | last post by:
Hi, I'm new to C#, please be patient :-) I am trying to pass an Arraylist (myAL) to a jagged array (myAL2) . The problem I have is that when I write the values to a file i do not get the values...
4
11263
by: archu007 | last post by:
hi i'm using the following statement in my application string strTArray = new string; strTArray = (string)(Session); when i run the application its giving the below error {"Unable to cast...
0
7254
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,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
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,...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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...

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.