473,387 Members | 1,621 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,387 software developers and data experts.

Error: may cause a runtime exception because it is a field of a marshal-by-reference

Hi,

I have a global structure that I declare within form1.cs, and I need to
reference from within other forms, everything seems to work okay at
runtime,
Everything works okay however I get the following warning when I compile:

Warning 2 Accessing a member on 'MYCMS.Form1.GLCurrentUserInfo' may cause a
runtime exception because it is a field of a marshal-by-reference class
C:\MYCMS\Form2.cs

This is my code and how/where I use it..., I'm not sure if I am using the
correct approach to storing a retreiving variables that I require
globally..,, if not I am very open to suggestions.

thanks...

I create it and make use of it in form1.cs using the folloiw code:

public struct UserInfo
{
public string userid;
public string password;
public string userlevel;
public decimal nemployeeid;
};
public UserInfo GLCurrentUserInfo;

GLCurrentUserInfo.userid = "someUserID";
then within another form, lets say form2.cs I wish to retreive then value
of it using:

Form1 oForm = (Form1)ParentForm;
this.txtAddedBy.Text = oForm.GLCurrentUserInfo.userid;


Mar 30 '06 #1
4 2050
Hello Rob,

What's the reason to use struct for this?

RD> I have a global structure that I declare within form1.cs, and I
RD> need to
RD> reference from within other forms, everything seems to work okay at
RD> runtime,
RD> Everything works okay however I get the following warning when I
RD> compile:
RD> Warning 2 Accessing a member on 'MYCMS.Form1.GLCurrentUserInfo' may
RD> cause a runtime exception because it is a field of a
RD> marshal-by-reference class C:\MYCMS\Form2.cs
RD>
RD> This is my code and how/where I use it..., I'm not sure if I am
RD> using the correct approach to storing a retreiving variables that I
RD> require globally..,, if not I am very open to suggestions.
RD>
RD> thanks...
RD>
RD> I create it and make use of it in form1.cs using the folloiw code:
RD>
RD> public struct UserInfo
RD> {
RD> public string userid;
RD> public string password;
RD> public string userlevel;
RD> public decimal nemployeeid;
RD> };
RD> public UserInfo GLCurrentUserInfo;
RD> GLCurrentUserInfo.userid = "someUserID";
RD>
RD> then within another form, lets say form2.cs I wish to retreive then
RD> value of it using:
RD>
RD> Form1 oForm = (Form1)ParentForm;
RD> this.txtAddedBy.Text = oForm.GLCurrentUserInfo.userid;
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

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

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello Rob,

What's the reason to use struct for this?


[cut]

LOL

Give up Rob :-)

You should be starting to realize by now that in 3 weeks time you'll have no
new sorting solutions but you'll still be getting people jumping into this
thread to tell you not to use structs.

Just because a lot of people say something doesn't make it so.......except
in this case.
Mar 30 '06 #3
Hi,

The reason for this struct is that I wish to assign user information read
from a database at login that will be available to the rest of the forms
throughout the application. I like using structs because it keeps
everything neat and tidy. I am new to programming in C#, I am much more
comfortable with vc++/MFC. Normally I would create a global variable, but
I don't really see, where, how I would do this. If this was a webform app
then I realize I could use a sessionid or use those new profile services. I
am looking for suggestions here. I don't think writing to the registry is
an option.

Anyway any, all help would be appreciated..

thanks,
"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello Rob,

What's the reason to use struct for this?

RD> I have a global structure that I declare within form1.cs, and I
RD> need to
RD> reference from within other forms, everything seems to work okay at
RD> runtime,
RD> Everything works okay however I get the following warning when I
RD> compile:
RD> Warning 2 Accessing a member on 'MYCMS.Form1.GLCurrentUserInfo' may
RD> cause a runtime exception because it is a field of a
RD> marshal-by-reference class C:\MYCMS\Form2.cs
RD> RD> This is my code and how/where I use it..., I'm not sure if I am
RD> using the correct approach to storing a retreiving variables that I
RD> require globally..,, if not I am very open to suggestions.
RD> RD> thanks...
RD> RD> I create it and make use of it in form1.cs using the folloiw code:
RD> RD> public struct UserInfo
RD> {
RD> public string userid;
RD> public string password;
RD> public string userlevel;
RD> public decimal nemployeeid;
RD> };
RD> public UserInfo GLCurrentUserInfo;
RD> GLCurrentUserInfo.userid = "someUserID";
RD> RD> then within another form, lets say form2.cs I wish to retreive
then
RD> value of it using:
RD> RD> Form1 oForm = (Form1)ParentForm;
RD> this.txtAddedBy.Text = oForm.GLCurrentUserInfo.userid;
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

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

Mar 30 '06 #4
Hi,

its okay I figured it out.. all I need to do is change my declaration from:

public UserInfo GLCurrentUserInfo;

TO:

public static UserInfo GLCurrentUserInfo;

and then I can just use it as is without casting the parentform..

thanks.


Mar 30 '06 #5

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

Similar topics

1
by: Sean Abrahams | last post by:
The following is a reprint of a message I sent to the tutor list a long time ago, that I haven't gotten around to discussing with anyone else and failed to hear a reply on the tutor list. Hoping...
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
8
by: Dinesh Jain | last post by:
Hi al,, I have written a code which displays directory listing of files from FTP server directory.I display all the files in a listview with its associated icons. To display icons, I get the...
6
by: Rich Wallace | last post by:
Hi all, I have a VB app that runs and manages individual XLS files within a single COM object. Upon processing the final fie, I attempt to close out the EXCEL object and release it using...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
5
by: ajos | last post by:
hi frnds, this is the way i ve written--> <html:text name="bdgtmastForm" property="publicity_code" size="5" maxlength="5"> but its giving me an error which seems irrelevent.. type Exception...
0
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk...
0
Dököll
by: Dököll | last post by:
Hey Gang! What do you make of this error: I am attempting to read an Access Table, while all seems well in the code, looks like it is asking me to format form fields, what are your...
2
by: pavanip | last post by:
Hi, I developed a windows application in Vb.Net 2003.It is working fine in this. But when I am trying to convert this into .Net 2005 I am getting this error. Class not registered...
3
by: naharol | last post by:
when i run this code i got an error .... can any body help me out ? <%@page import="java.sql.*"%> <form action="index.jsp?pg=13" method="post"> <table> <tr><td>class:</td><td><select name="cl">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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,...

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.