Is it possible to add a Finalizer to a CodeDom generated class (other than using CodeSnippetTypeMember)?
I couldn't find any information about it on MSDN.
This was a known bug in .NET Framework and was reported some time back at
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackId=FDBK48431
But the link above is currently not working. You can view it using internet archive on the following link
http://web.archive.org/web/20080224200911rn_2/connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97599
I am not sure whether it was fixed or not.
Related
I can't seem to find it in their github repository. If someone could be so kind as to find the definitions to it, I'd appreciate it.
Closest I've got is the following partial class definition (method definition at L340.)
EDIT: I don't see why this was closed. I'm not asking for any recommendations. I'm asking for help in finding a given line of code, in a huge open source project.
That can be found in Microsoft's Reference Source for the .NET Framework. A quick search for .NET ForEach source came up with it. Here's the bit you might be interested in
The .NET Core version is also available as a convenient source browser.
You can also find it where you were looking for, in the dotnet/runtime repo over here. Apparently, mscorlib is, as far as I can tell (didn't investigate profusely), mapped to System.Private.CoreLib. That's where you'll probably find the sources for any mscorlib related things (e.g. code for List<T>).
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs
i think this is what you want.
I am putting together a simple (sandboxed) module system for an application that I am writing in order to allow loading and execution of 'modules' written by others (untrusted code) while locking down permissions (File.IO, etc) to minimize the risk of malicious code.
Based on the article: How to: Run Partially Trusted Code in a Sandbox
In step 2: Sign the assembly:
StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();
I get the following error:
System.ArgumentException: 'A null StrongName was found in the full trust assembly list.'
Further investigation, sure enough, fullTrustAssembly is in fact null, and digging a bit deeper the .GetHostEvidence<StrongName>(); is the method that is returning null.
I have found a solution here (that works): A null strongname was found in the full trust assembly list sandbox application that looks like:
StrongName fullTrustAssembly = new StrongName(
new StrongNamePublicKeyBlob(typeof(Sandboxer).Assembly.GetName().GetPublicKey()),
typeof(Sandboxer).Assembly.GetName().Name,
typeof(Sandboxer).Assembly.GetName().Version);
However, the person that provided the answer to that question stated:
Prior to .net framework 4.0, you could not obtain a strongName by calling GetHostEvidence. Change the version of your .net framework.
I am using .NET Framework 4.8, so according to that statement, and the original tutorial, the GetHostEvidence() should be working.
1. Why is GetHostEvidence<StrongName>() not working as per the original tutorial?
2. What is the real difference between the two different methods of obtaining a signed StrongName above?
Bonus points
Google has not been my friend with finding current implementations and tutorials to accomplish my task in this sandboxed module manager portion of my project. Are there any good resources (besides the .NET documentation) that can give more detail to understanding how it all works? Most of what I can find is way out of date (10+ years old). Are there more current strategies for achieving this. (note: I have looked into Managed Extensibility Framework (MEF) and feel it's great for another separate part of the project I am working on, but seems like overkill for this part. I have also looked at System.Addin (MAF?) but all I can find is Web/ASP related information for that, to which most of it is also extremely outdated)
#Aaron Murray
Did you sign your assembly which has the SandBox class? if not, you can try the instructions mentioned here https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-sign-an-assembly-with-a-strong-name
If the assembly is not signed, then it is expected to have typeof(Sandboxer).Assembly.Evidence.GetHostEvidence() returning null.
the doc https://learn.microsoft.com/en-us/dotnet/framework/misc/how-to-run-partially-trusted-code-in-a-sandbox is explicity mentioning the signing requirements in step #2
Thanks.
.NET Framework proposes "///" for documentation in code. However, when I see the .NET library, I see they are using normal comment starting with "//". Also, I see that due to that the APIs look clean. See below screenshot:
Notice that collapsed box shows only ellipses("...") and are placed in front of method declaration. But when I try to follow the same, I do not get the desired result. See below screenshot:
Notice that I get "//" characters along with ellipses("..."). Plus, I cannot get the field/method and comment to be placed on the same line.
How do I achieve the same result? Is there any trick that I am missing here?
However, when I see the .NET library
You're not looking at the actual source code. That's just a representation of the metadata, generated for you by Visual Studio. It looks like some documentation is being pulled in from somewhere (that doesn't happen on my box in the way I've just tried it, but that's a different matter). You can tell this isn't real source code because there are constructors declared with no body.
If you look at genuine source code, e.g. ReferenceSource for TcpClient you'll see triple-slash comments. Interestingly, the .NET Core code doesn't have any XML comments either, but I suspect that's because they're defined elsewhere, as part of .NET Standard. (There's an XML file in the dotnet-api-docs repo, but it's not immediately clear what that's generated from...)
When it comes to your own code, I'd strongly recommend just using the /// syntax. /** ... */ should work as well, but I don't remember ever seeing that in C# code. // is not a valid way of writing an XML comment in C#.
I am using OracleBulkCopy Class with reference to Oracle.DataAccess.dll. I want to use Oracle.ManagedDataAccess.dll for easy deployment. But then I got build error "OracleBulkCopy not found"
Does anyone know why OracleBulkCopy is not included in Oracle.ManagedDataAccess.dll?
You are correct. At the time of this writing OracleBulkCopy is not supported in ODP.NET, Managed Driver.
The reason is is not included was simply a matter of feature priority. As the Managed Driver becomes more feature complete, eventually the OracleBulkCopy class will be added.
In the future, anyone can look at the "Differences between the ODP.NET Managed Driver and Unmanaged Driver" section of the most recent ODP.NET book to see what is not supported:
https://docs.oracle.com/cd/E56485_01/win.121/e55744/intro004.htm#ODPNT8146
Please vote for it at the Oracle Feature Request page:
https://apex.oracle.com/pls/apex/f?p=18357:39:28710406382793::NO::P39_ID:27881
If we get enough votes, they may implement it.
Good news, this feature is part of Oracle.ManagedDataAccess.Client namespace. :)
I would like to be able to view the code running behind the scenes when I call specific functions in C# - is it possible to find and decompile these code libraries? MSDN often has usage examples and plain-text explanations, but in some cases I want to see code execution and which functions call each other.
As a specific example, I would like to crack open the System.Web.UI.Page class. How can I view the source code for this class, not the documentation?
You can download the .NET Framework Reference sources from here:
http://referencesource.microsoft.com/netframework.aspx
This includes most (if not all?) of the BCL libraries.. such as Dictionary, List, String, etc.
During debug mode on,if you want to see decompiled code on the current cursor position in visual studio 2022, press ctrl+F11
This will take you to the current disassembly.