waf / CSharpRepl

A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.
https://fuqua.io/CSharpRepl/
Mozilla Public License 2.0
2.93k stars 113 forks source link

System.AccessViolationException #202

Closed GroophyLifefor closed 1 year ago

GroophyLifefor commented 1 year ago

Version

0.4.0

What happened?

I don't think this is related to this project, but this code causes error including unsafe, I was wondering what is causing the error? and why does the compiler allow it?

unsafe { *((byte*)0xDEADBEEF) = 0x50; }
> unsafe { *((byte*)0xDEADBEEF) = 0x50; }
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at Submission#3+<<Initialize>>d__0.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)

Trace

2022-12-02T18:15:01 - Trace session starting
2022-12-02T18:15:01 - Starting background initialization
2022-12-02T18:15:01 - Available Reference Assemblies: "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref": ["5.0.0", "6.0.6", "6.0.9", "7.0.0-rc.1.22426.10"]
2022-12-02T18:15:01 - Available Implementation Assemblies: "C:\Program Files\dotnet\shared\Microsoft.NETCore.App": ["3.1.23", "5.0.15", "5.0.17", "6.0.6", "6.0.9", "7.0.0-preview.3.22175.4", "7.0.0-rc.1.22426.10"]
2022-12-02T18:15:01 - .NET Version: Microsoft.NETCore.App / 6.0.9
2022-12-02T18:15:01 - Reference Assembly Paths: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.9\ref\net6.0
2022-12-02T18:15:01 - Implementation Assembly Paths: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.9
2022-12-02T18:15:01 - Shared Framework Paths: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.9
2022-12-02T18:15:01 - Loaded Reference Assemblies: "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.9\ref\net6.0": ["System.Globalization.dll", "System.Globalization.Extensions.dll", "System.IO.Compression.Brotli.dll", "System.IO.Compression.dll", "System.IO.Compression.FileSystem.dll", "System.IO.Compression.ZipFile.dll", "System.IO.dll", "System.IO.FileSystem.AccessControl.dll", "System.IO.FileSystem.dll", "System.IO.FileSystem.DriveInfo.dll", "System.IO.FileSystem.Primitives.dll", "System.IO.FileSystem.Watcher.dll", "System.IO.IsolatedStorage.dll", "System.Threading.Channels.dll", "System.Threading.dll", "System.Threading.Overlapped.dll", "System.Threading.Tasks.Dataflow.dll", "System.Threading.Tasks.dll", "System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Parallel.dll", "System.Threading.Thread.dll", "System.Threading.ThreadPool.dll", "System.Threading.Timer.dll", "System.Transactions.dll", "System.Transactions.Local.dll", "System.ValueTuple.dll", "System.Security.Cryptography.X509Certificates.dll", "System.Security.dll", "System.Security.Principal.dll", "System.Security.Principal.Windows.dll", "System.Security.SecureString.dll", "System.ServiceModel.Web.dll", "System.ServiceProcess.dll", "System.Text.Encoding.CodePages.dll", "System.Text.Encoding.dll", "System.Text.Encoding.Extensions.dll", "System.Text.Encodings.Web.dll", "System.Text.Json.dll", "System.Text.RegularExpressions.dll", "System.Diagnostics.DiagnosticSource.dll", "System.Diagnostics.FileVersionInfo.dll", "System.Diagnostics.Process.dll", "System.Diagnostics.StackTrace.dll", "System.Diagnostics.TextWriterTraceListener.dll", "System.Diagnostics.Tools.dll", "System.Diagnostics.TraceSource.dll", "System.Diagnostics.Tracing.dll", "System.dll", "System.Drawing.dll", "System.Drawing.Primitives.dll", "System.Dynamic.Runtime.dll", "System.Formats.Asn1.dll", "System.Globalization.Calendars.dll", "System.Net.WebSockets.dll", "System.Numerics.dll", "System.Numerics.Vectors.dll", "System.ObjectModel.dll", "System.Reflection.DispatchProxy.dll", "System.Reflection.dll", "System.Reflection.Emit.dll", "System.Reflection.Emit.ILGeneration.dll", "System.Reflection.Emit.Lightweight.dll", "System.Reflection.Extensions.dll", "System.Reflection.Metadata.dll", "System.Reflection.Primitives.dll", "System.Reflection.TypeExtensions.dll", "System.Net.Mail.dll", "System.Net.NameResolution.dll", "System.Net.NetworkInformation.dll", "System.Net.Ping.dll", "System.Net.Primitives.dll", "System.Net.Requests.dll", "System.Net.Security.dll", "System.Net.ServicePoint.dll", "System.Net.Sockets.dll", "System.Net.WebClient.dll", "System.Net.WebHeaderCollection.dll", "System.Net.WebProxy.dll", "System.Net.WebSockets.Client.dll", "System.IO.MemoryMappedFiles.dll", "System.IO.Pipes.AccessControl.dll", "System.IO.Pipes.dll", "System.IO.UnmanagedMemoryStream.dll", "System.Linq.dll", "System.Linq.Expressions.dll", "System.Linq.Parallel.dll", "System.Linq.Queryable.dll", "System.Memory.dll", "System.Net.dll", "System.Net.Http.dll", "System.Net.Http.Json.dll", "System.Net.HttpListener.dll", "System.Runtime.Serialization.dll", "System.Runtime.Serialization.Formatters.dll", "System.Runtime.Serialization.Json.dll", "System.Runtime.Serialization.Primitives.dll", "System.Runtime.Serialization.Xml.dll", "System.Security.AccessControl.dll", "System.Security.Claims.dll", "System.Security.Cryptography.Algorithms.dll", "System.Security.Cryptography.Cng.dll", "System.Security.Cryptography.Csp.dll", "System.Security.Cryptography.Encoding.dll", "System.Security.Cryptography.OpenSsl.dll", "System.Security.Cryptography.Primitives.dll", "System.ComponentModel.Annotations.dll", "System.ComponentModel.DataAnnotations.dll", "System.ComponentModel.dll", "System.ComponentModel.EventBasedAsync.dll", "System.ComponentModel.Primitives.dll", "System.ComponentModel.TypeConverter.dll", "System.Configuration.dll", "System.Console.dll", "System.Core.dll", "System.Data.Common.dll", "System.Data.DataSetExtensions.dll", "System.Data.dll", "System.Diagnostics.Contracts.dll", "System.Diagnostics.Debug.dll", "Microsoft.CSharp.dll", "Microsoft.VisualBasic.Core.dll", "Microsoft.VisualBasic.dll", "Microsoft.Win32.Primitives.dll", "Microsoft.Win32.Registry.dll", "mscorlib.dll", "netstandard.dll", "System.AppContext.dll", "System.Buffers.dll", "System.Collections.Concurrent.dll", "System.Collections.dll", "System.Collections.Immutable.dll", "System.Collections.NonGeneric.dll", "System.Collections.Specialized.dll", "System.Resources.Reader.dll", "System.Resources.ResourceManager.dll", "System.Resources.Writer.dll", "System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.VisualC.dll", "System.Runtime.dll", "System.Runtime.Extensions.dll", "System.Runtime.Handles.dll", "System.Runtime.InteropServices.dll", "System.Runtime.InteropServices.RuntimeInformation.dll", "System.Runtime.Intrinsics.dll", "System.Runtime.Loader.dll", "System.Runtime.Numerics.dll", "System.Web.dll", "System.Web.HttpUtility.dll", "System.Windows.dll", "System.Xml.dll", "System.Xml.Linq.dll", "System.Xml.ReaderWriter.dll", "System.Xml.Serialization.dll", "System.Xml.XDocument.dll", "System.Xml.XmlDocument.dll", "System.Xml.XmlSerializer.dll", "System.Xml.XPath.dll", "System.Xml.XPath.XDocument.dll", "WindowsBase.dll"]
2022-12-02T18:15:01 - Loaded Implementation Assemblies: "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.9": ["System.Reflection.Emit.ILGeneration.dll", "System.Reflection.Emit.Lightweight.dll", "System.Reflection.Extensions.dll", "System.Reflection.Metadata.dll", "System.Reflection.Primitives.dll", "System.Reflection.TypeExtensions.dll", "System.Resources.Reader.dll", "System.Resources.ResourceManager.dll", "System.Resources.Writer.dll", "System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.VisualC.dll", "System.Runtime.dll", "System.Runtime.Extensions.dll", "System.Runtime.Handles.dll", "System.Runtime.InteropServices.dll", "System.Runtime.InteropServices.RuntimeInformation.dll", "System.Runtime.Intrinsics.dll", "System.Runtime.Loader.dll", "System.Security.SecureString.dll", "System.ServiceModel.Web.dll", "System.ServiceProcess.dll", "System.Text.Encoding.CodePages.dll", "System.Text.Encoding.dll", "System.Text.Encoding.Extensions.dll", "System.Text.Encodings.Web.dll", "System.Text.Json.dll", "System.Text.RegularExpressions.dll", "System.Threading.Channels.dll", "System.Threading.dll", "System.Threading.Overlapped.dll", "System.Threading.Tasks.Dataflow.dll", "System.Threading.Tasks.dll", "System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Parallel.dll", "System.Threading.Thread.dll", "System.Threading.ThreadPool.dll", "System.Globalization.Calendars.dll", "System.Globalization.dll", "System.Globalization.Extensions.dll", "System.IO.Compression.Brotli.dll", "System.IO.Compression.dll", "System.IO.Compression.FileSystem.dll", "System.IO.Compression.ZipFile.dll", "System.IO.dll", "System.IO.FileSystem.AccessControl.dll", "System.IO.FileSystem.dll", "System.IO.FileSystem.DriveInfo.dll", "System.IO.FileSystem.Primitives.dll", "System.IO.FileSystem.Watcher.dll", "System.IO.IsolatedStorage.dll", "System.IO.MemoryMappedFiles.dll", "System.IO.Pipes.AccessControl.dll", "System.IO.Pipes.dll", "System.Data.Common.dll", "System.Data.DataSetExtensions.dll", "System.Data.dll", "System.Diagnostics.Contracts.dll", "System.Diagnostics.Debug.dll", "System.Diagnostics.DiagnosticSource.dll", "System.Diagnostics.FileVersionInfo.dll", "System.Diagnostics.Process.dll", "System.Diagnostics.StackTrace.dll", "System.Diagnostics.TextWriterTraceListener.dll", "System.Diagnostics.Tools.dll", "System.Diagnostics.TraceSource.dll", "System.Diagnostics.Tracing.dll", "System.dll", "System.Drawing.dll", "System.Drawing.Primitives.dll", "System.Dynamic.Runtime.dll", "System.Formats.Asn1.dll", "System.Runtime.Numerics.dll", "System.Runtime.Serialization.dll", "System.Runtime.Serialization.Formatters.dll", "System.Runtime.Serialization.Json.dll", "System.Runtime.Serialization.Primitives.dll", "System.Runtime.Serialization.Xml.dll", "System.Security.AccessControl.dll", "System.Security.Claims.dll", "System.Security.Cryptography.Algorithms.dll", "System.Security.Cryptography.Cng.dll", "System.Security.Cryptography.Csp.dll", "System.Security.Cryptography.Encoding.dll", "System.Security.Cryptography.OpenSsl.dll", "System.Security.Cryptography.Primitives.dll", "System.Security.Cryptography.X509Certificates.dll", "System.Security.dll", "System.Security.Principal.dll", "System.Security.Principal.Windows.dll", "Microsoft.CSharp.dll", "Microsoft.VisualBasic.Core.dll", "Microsoft.VisualBasic.dll", "Microsoft.Win32.Primitives.dll", "Microsoft.Win32.Registry.dll", "mscorlib.dll", "netstandard.dll", "System.AppContext.dll", "System.Buffers.dll", "System.Collections.Concurrent.dll", "System.Collections.dll", "System.Collections.Immutable.dll", "System.Collections.NonGeneric.dll", "System.Collections.Specialized.dll", "System.ComponentModel.Annotations.dll", "System.ComponentModel.DataAnnotations.dll", "System.ComponentModel.dll", "System.ComponentModel.EventBasedAsync.dll", "System.ComponentModel.Primitives.dll", "System.ComponentModel.TypeConverter.dll", "System.Configuration.dll", "System.Console.dll", "System.Core.dll", "System.Threading.Timer.dll", "System.Transactions.dll", "System.Transactions.Local.dll", "System.ValueTuple.dll", "System.Web.dll", "System.Web.HttpUtility.dll", "System.Windows.dll", "System.Xml.dll", "System.Xml.Linq.dll", "System.Xml.ReaderWriter.dll", "System.Xml.Serialization.dll", "System.Xml.XDocument.dll", "System.Xml.XmlDocument.dll", "System.Xml.XmlSerializer.dll", "System.Xml.XPath.dll", "System.Xml.XPath.XDocument.dll", "WindowsBase.dll", "System.IO.UnmanagedMemoryStream.dll", "System.Linq.dll", "System.Linq.Expressions.dll", "System.Linq.Parallel.dll", "System.Linq.Queryable.dll", "System.Memory.dll", "System.Net.dll", "System.Net.Http.dll", "System.Net.Http.Json.dll", "System.Net.HttpListener.dll", "System.Net.Mail.dll", "System.Net.NameResolution.dll", "System.Net.NetworkInformation.dll", "System.Net.Ping.dll", "System.Net.Primitives.dll", "System.Net.Quic.dll", "System.Net.Requests.dll", "System.Net.Security.dll", "System.Net.ServicePoint.dll", "System.Net.Sockets.dll", "System.Net.WebClient.dll", "System.Net.WebHeaderCollection.dll", "System.Net.WebProxy.dll", "System.Net.WebSockets.Client.dll", "System.Net.WebSockets.dll", "System.Numerics.dll", "System.Numerics.Vectors.dll", "System.ObjectModel.dll", "System.Private.CoreLib.dll", "System.Private.DataContractSerialization.dll", "System.Private.Uri.dll", "System.Private.Xml.dll", "System.Private.Xml.Linq.dll", "System.Reflection.DispatchProxy.dll", "System.Reflection.dll", "System.Reflection.Emit.dll"]
2022-12-02T18:15:02 - MEF Default Assemblies: C:\Users\GROOPHY\.dotnet\tools\.store\csharprepl\0.4.0\csharprepl\0.4.0\tools\net6.0\any\Microsoft.CodeAnalysis.Workspaces.dll, C:\Users\GROOPHY\.dotnet\tools\.store\csharprepl\0.4.0\csharprepl\0.4.0\tools\net6.0\any\Microsoft.CodeAnalysis.CSharp.Workspaces.dll, C:\Users\GROOPHY\.dotnet\tools\.store\csharprepl\0.4.0\csharprepl\0.4.0\tools\net6.0\any\Microsoft.CodeAnalysis.Features.dll, C:\Users\GROOPHY\.dotnet\tools\.store\csharprepl\0.4.0\csharprepl\0.4.0\tools\net6.0\any\Microsoft.CodeAnalysis.CSharp.Features.dll
2022-12-02T18:15:02 - Background initialization complete
2022-12-02T18:15:02 - Warm-up Starting
2022-12-02T18:15:04 - Warm-up Complete
kindermannhubert commented 1 year ago

No, it's not related to this project. Your code tries to write to some random place in memory that is protected by OS. Pointers are allowed in C#, but then you need to know (that's why unsafe is needed) what you are doing (and this is not a valid usage).

GroophyLifefor commented 1 year ago

Can you give an example of correct usage? it could be anything, i wonder why that way.

kindermannhubert commented 1 year ago

Here's description + examples: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code#pointer-types