all groups > visual studio .net general > march 2006 >
You're in the

visual studio .net general

group:

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


Error: may cause a runtime exception because it is a field of a marshal-by-reference Rob Dob
3/29/2006 8:35:08 PM
visual studio .net general:
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;





Re: Error: may cause a runtime exception because it is a field of a marshal-by-reference Rob Dob
3/30/2006 10:14:17 AM
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.



AddThis Social Bookmark Button