Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 15th, 2015, 12:45 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I can't access public varable.

Warning 1 Accessing a member on 'WindowsFormsApplication1.NewItemForm.PriceEach' may cause a runtime exception because it is a field of a marshal-by-reference class C:\Users\Mark\Desktop\Visual C# Folders\C#24 hours completed excersises\Try13\WindowsFormsApplication1\Form1.cs 30 34 WindowsFormsApplication1

Hi

I need help with TryIt 13 exercise. When I click OK button to accept fields on the main form I get above message . I am using Visual Studio 2010 professional , academic edition. Tried to re-assign fields to local variables and display them but it did not help.No idea why original (solution) program work and mine does not. Thanks for help.

Mark
Reply With Quote
  #2 (permalink)  
Old February 15th, 2015, 01:39 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Mark,

I don't know why it would do that. I certainly can't imagine why my solution would work but yours wouldn't, at least not for the fields.

But it seems to not like the fields, so you may be able to work around it by converting them into properties instead of fields. Try using these declarations:

Code:
public string ItemName { get; set; }
public decimal PriceEach { get; set; }
public decimal Quantity { get; set; }
public decimal TotalPrice { get; set; }
Let me know if that works.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #3 (permalink)  
Old February 16th, 2015, 02:17 PM
Friend of Wrox
Points: 526, Level: 8
Points: 526, Level: 8 Points: 526, Level: 8 Points: 526, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 127
Thanks: 1
Thanked 10 Times in 10 Posts
Default

it is probably because you are calling a method of a value type that is defined in a class that implements MarshalByRefObject. Without looking at the code I am assuming its a System.Windows.Forms.Form.

check out https://msdn.microsoft.com/en-us/library/x524dkh4.aspx for a work around.
Reply With Quote
  #4 (permalink)  
Old February 16th, 2015, 10:51 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thank you guys for trying help me. I re-started my computer. I was able to run program. It gave me warnings , but no errors. Converting fields to properties did not help. This warning is generated only by numeric type fields, string fields work fine. I run identical program using VB and everything was fine. Thanks

Mark
Reply With Quote
  #5 (permalink)  
Old February 17th, 2015, 11:44 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Strange. Did you try the workaround mmorgan30 mentioned? The main form would need to save the field values into variables and then use the variables' ToString methods.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a class member with the public access specifier beszpilman BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 4 December 21st, 2009 12:40 PM
Access modifiers private and public markhh Java Basics 3 February 21st, 2008 04:56 AM
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 09:38 AM
Public classes myousman ASP.NET 1.0 and 1.1 Professional 4 October 23rd, 2006 02:18 PM
public functions stojkovmarjan ASP.NET 2.0 Basics 1 September 19th, 2006 04:57 PM



All times are GMT -4. The time now is 06:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.