Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old February 15th, 2015, 01:39 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
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!)
 
Old February 16th, 2015, 02:17 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 136
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.
 
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
 
Old February 17th, 2015, 11:44 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
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!)




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 08:38 AM
Public classes myousman ASP.NET 1.0 and 1.1 Professional 4 October 23rd, 2006 01:18 PM
public functions stojkovmarjan ASP.NET 2.0 Basics 1 September 19th, 2006 03:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.