.NET Security Permissions

Hi All,

I have some code that I wrote a while ago that is a file browser. I use the call
Environment.GetLogicalDrives() to return the drives on my computer. This code used to work, but with the new framework I am not getting "Because of security restriction the type ... cannot be accessed".

How do I give my application the sufficient permissions it needs.

Here is my code to get the drives:

publicstring [] GetDrives()
{
string [] drives =Environment.GetLogicalDrives();
return drives;
}

Thanks in advance,
Brent

PS - If this post is not in the correct forum please let me know.

[930 byte] By [BrentLak] at [2007-12-17]
# 1
Where are you running this application from?

For example is your application running from a network location or from the Internet?

DavidM.Kean at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
You should also verify that "code access security" settings are not causing this behaviour.

That means: If you have already tried to run your application from the local machine ( that could imply copying the executable onto your local FileSystem first ) and get the same error, you should verify that the "Security > ClickOnce Settings" in "Project > YourProjectName Properties" are not demanding less rights than required or are completely turned off.
Kind regards,
Markus

MarkusEilers at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
Hi Markus,

It seems like the project settings for a class library type project do not include the security tab :(

Brent

BrentLak at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Hi Brent,

well :) ... Although that would be an interesting concept, I guess the invoking application should not inherit rights from an assembly.

Taking the information that you are talking about

  • an assembly
  • used by a windows service
  • on a different machine
  • exposing a remoting interface

as completely new and view-changing, PLEASE supply all necessary information.
I know I have lots of time, but I don't like to play darts in the dark.

Where does the error pop up ?
Kind regards,
Markus

MarkusEilers at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
Sorry Markus, I will try and give you all information below.

I am writing a remote administration application. As a talked about before, the server which is run through a windows service exposes my remote object. The remote object is just a class library(dll). The client uses an interface(the remote object implements this interface) to the remote object to make calls to the object exposed by the server.

I started this code a long time ago, I believe in the 1.0 framework. I am just now comming back to it. It used to work back in 1.0 but now it does not. Right now both the client and the server are running on the same box here as I am testing it. I have also tested it on two different boxes and I get the same error.

I also get the error when the client app calls the remote method to get directories.

client making the call which causes the exception:
(resService is my client reference to the remote object hosted on the server)

DirectoryInfo dir = resService.GetDirInfo(address);
DirectoryInfo [] subDirs = resService.GetDirs(dir); < this line causes the exception

remote method on the server being called:

public DirectoryInfo [] GetDirs(DirectoryInfo dir)
{
DirectoryInfo [] subDirs = dir.GetDirectories();
return subDirs;
}

The exact error message is this: its a bit long....lol

System.Runtime.Serialization.SerializationException was unhandled
Message="Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed."
Source="mscorlib"
StackTrace:
Server stack trace:
at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Interface.IRemotingExampleService.GetDirs(DirectoryInfo dir)
at Client.Form1.OpenFolder(ListView lvw, String address, ESort order) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 1428
at Client.Form1.tvw_AfterSelect(Object sender, TreeViewEventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 1142
at System.Windows.Forms.TreeView.TvnSelected(NMTREEVIEW* nmtv)
at System.Windows.Forms.TreeView.WmNotify(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmNotify(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, IntPtr lparam)
at System.Windows.Forms.TreeView.set_SelectedNode(TreeNode value)
at Client.Form1.ShowDrives(TreeView tvw) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 1396
at Client.Form1.SecondExplorer_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 1333
at Client.Form1.ToolBar_ButtonClick(Object sender, ToolBarButtonClickEventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 1158
at System.Windows.Forms.ToolBar.WmReflectCommand(Message& m)
at System.Windows.Forms.ToolBar.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolBar.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Client.Form1.Main() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Remoting\Client\Form1.cs:line 931
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Thanks for your time and help.
Brent

BrentLak at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 6
Hey Markus or anyone else,

Does anyone have an idea on what I can do to grant my app permissions. I do not know much about security permissions... :(

Thanks,
Brent

BrentLak at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 7

Hello Brent,

You may be encountering one of the security lockdown changes made between Framework/Remoting 1.0 and Framework/Remoting 1.1 - covering serialization of objects, when returned to the client.

You can see more detail at: http://www.gotdotnet.com/team/changeinfo/Backwards1.0to1.1/default.aspx#00000153

Hope that helps,
Stephen Fisher [Microsoft Common Language Runtime - Security: Developer]
http://blogs.msdn.com/stfisher

StephenFisher-MS at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified