Howto take a glimpse into mscorlib? - c#

I want to read data into RSAParameters structure ( RSAParameters ) and did check twice, that the data is correct. But still, I get an error "invalid data" exception for this:
bei System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
bei System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
bei System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
How can I take a look into the source code to check why _ImportKeys is throwing an exception? I have no experience with .dll 'decryption'..are there any symbols to reference somewhere for visual studio 8.0? Thank you.

Use .NET Reflector to disassemble the DLL you want to examine.

You can also use JetBrains dotPeek. It is 100% free.

Related

.NET MySql ArgumentNullException on Open in GetCustomAttributes

I'm trying to swap database providers out in .NET code to MariaDB. As part of that, I'm trying to open a MySqlConnection. This in turn results in an argument null execption with a message of: "Value cannot be null. Parameter name: element" and the following call stack:
mscorlib.dll!System.Attribute.GetCustomAttributes(System.Reflection.Assembly element, System.Type attributeType, bool inherit) Line 756 C#
mscorlib.dll!System.Attribute.GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType, bool inherit) Line 814 C#
mscorlib.dll!System.Reflection.CustomAttributeExtensions.GetCustomAttribute<System.Runtime.Versioning.TargetFrameworkAttribute>(System.Reflection.Assembly element) Line 27 C#
> MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnectAttrs.InitFramework() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnectAttrs.MySqlConnectAttrs() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(bool reset) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.Authenticate(string authMethod, bool reset) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.Open() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Driver.Open() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) Unknown
MySql.Data.dll!MySql.Data.Failover.FailoverManager.AttemptConnection(MySql.Data.MySqlClient.MySqlConnection connection, string originalConnectionString, out string connectionString, bool mySqlPoolManager) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnection.Open() Unknown
(My code below this point)
I'm using a connection string similar to:
<add name="MyMariaDatabase" connectionString="server=myservername.rds.amazonaws.com;port=3306; database=mydb;uid=myuser; pwd=mypassword" providerName="MySql.Data.MySqlClient" />
Sample connection code:
using (var client = new MySql.Data.MySqlClient.MySqlConnection(connStr))
{
client.Open();
var result = client.ExecuteScalar(someSqlStatement);
}
This is all running in .NET Framework 4.7.2 and MySQL.Data 8.0.19.
Any idea what's going wrong? The error seems deep inside the framework and it's not giving me helpful information.
You're encountering bug 95242, a known problem in Oracle's MySQL Connector/NET (aka MySql.Data).
I would recommend switching to MySqlConnector, an OSS MySQL and MariaDB client library. As well as fixing many bugs in Connector/NET and adding true async I/O support, it is independent of Oracle so it has support for MariaDB-specific features such as the GSSAPI authentication plugin and batch support.
Your Port must be seperated by semicolon.
Instead of
"server=myservername.rds.amazonaws.com,3306; database=mydb;uid=myuser; pwd=mypassword"
use this Connenction string
"Server=myservername.rds.amazonaws.com;Port=3306;Database=mydb;Uid=myuser;Pwd=mypassword;"

What does +number in the stack trace mean

I have an error and this is shown:
[OverflowException: Value was either too large or too small for a Decimal.]
System.Decimal..ctor(Double value) +0
System.Decimal.op_Explicit(Double value) +30
MyMethod(int myParameter) +5174
AnotherMethod(int myParameter) ....
What does +5174 mean?
It's not a line number.
It will be the IL offset, this happens when no PDB files / debug information are present.
You can have PDB data generated for release assemblies, which makes tracking down issues much more straight forward.

Compiler Issue in Windows 7: A generic error occurred in GDI+

We have an application that we need to begin testing and developing in Windows 7 environment. It works fine compiling under WinXP in VS2008, no problems. However when I went to compile it on a windows 7 machine using VS2008 today I get the following error:
Error 12 The "GenerateResource" task failed unexpectedly.
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(MemoryStream stream)
at System.Drawing.Image.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter)
at System.Resources.ResourceWriter.Generate()
at System.Resources.ResourceWriter.Dispose(Boolean disposing)
at System.Resources.ResourceWriter.Close()
at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(IResourceWriter writer)
at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(String filename)
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, List`1 inputs, List`1 outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass)
at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, List`1 inputs, List`1 outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass)
at Microsoft.Build.Tasks.GenerateResource.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
I cannot for the life of me run this one down. I have visited the msdn forums and find that it is an issue for a lot of people, but no consistent solution has been provided by MS or anyone else.
Has anyone seen this before and fixed it? Please advise is needed!
Thanks
I compiled using the command line msbuild and that identified the problem location.
It was a resx file in a class which had one unused image in it. I removed that and all was good again. Can build fine now.
After hours of troubleshooting, I opened and built the project using the VS 2010 command line prompt using MSBUILD "my solution file path here". This provided a more visible sequence of build events, and I found my project was failing just after it compiled form 16. The forms compiling appeared to be going in order of the objects in the solution explorer. So I checked the next form and found it contained a picture box. I also checked the form after that one and found I could not open the designer without errors(object reference not set to instance of object). So apparently, the problem was now two-fold.
To resolve I had to remove the picture box object from the first form I identified as problematic (it was not being used any way) as it appeared to be corrupted. I found the second form with the null reference exception was using a user control. The code for the constructor of the user control was attempting to pass an object to a container before calling InitializeComponent(). This created the null reference since the container hadn't event been created in InitializeComponent when the problematic code was called.
After resolving the issues in the above paragraph my solution compiled under Windows 7.
There is a GDI update for Windows 7, I think, if I'm not mistaken. Maybe that will solve the issue. Does your solution build using Msbuild on the commsnd line?
Do you use TIFF images in your app?
Some time ago, I also had a problem with TIFF images as part of reports that wouldn't compile under Win7 x64 although it compiled like a charm under Vista x86. The error message also involved GDI+. I saved the images under a different format (PNG) and the problem vanished.
At the time (around March 2011), I first ensured that my Windows was up-to-date but it didn't solve the problem. So maybe there is such an update as mentionned by Erik but it didn't come through Windows Update back then (Maybe it's newer).
Delete the resources from the resource manager (right click on each and delete) then add them back. for me it solve the problem.
i had same problem.
i just used msbuild myProject.sln command and it fixed and built successfully with no errors! now i can manually build my solution.
no need to reAdding my resources

How to decompile complex BAML to valid XAML

I tried ILSpy, but it failed:
System.NotImplementedException: StaticResourceStart
в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ProcessNext()
в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ReadInternal()
в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.Read()
в System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
в System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
в System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
в ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
в ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadBaml(AvalonEditTextOutput output)
в ILSpy.BamlDecompiler.BamlResourceEntryNode.<>c__DisplayClass3.<View>b__1()
I tried Baml Viewer for .Net Reflector, but it was unable to generate valid XAML.
The main problem was with Binding that reference to wrong StaticResource.
For example (namedViews is CollectionViewSource):
Visibility="{Binding Path=Value, Converter={StaticResource namedViews}}"
ToolTip="{StaticResource namedViews}"
What other applications exist to decompile BAML? Any patch to BAML Viewer?
Not sure if this will help you, but if you can run the application, you can use Snoop to run through the structure of a WPF application.
Other options:
dotPeek (but I believe it needs the Baml4dotPeek plugin which is based on Baml Viewer for Reflector, which, as you said, didn't work.)
JustDecompile (you have to register with Telerik, I believe)
Woodstock for WPF
I've only tried Snoop and like it very much, but that didn't seem to solve your problem.

High performance RSA implementation for C# or C

I have an webservice that performs many RSA-signature operations. I use the CryptograhyProvider from .net. This uses the unmanaged CyptoAPI from Windows.
I often have this error:
System.Security.Cryptography.CryptographicException: Der RPC-Server
ist für diesen Vorgang zu stark ausgelastet. [=The rpc server is too
busy to complete the transaction]
bei
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32
hr) bei
System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP,
Int32 keyNumber, CspProviderFlags flags, Object cspObject,
SafeKeyHandle& hKey) bei
System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters
parameters)
Instead of trying to fix this, I'd rather replace my RSA-signing operation with an DLLImport to a high performance RSA C implementation.
Does someone know one or can recommend one?
Is OpenSSL faster than MS CryptoApi?
I also suspect that loading the key might cause serious overhead.
Thanks!
I would recommend OpenSSL but i dont know the comparison with MS CryptoAPI. Its simple to use and documentation is extensive along with sample source code.
Check the detailed description of the APIs here.
You may also want to consider NSS. This is 2 years old, but could still be worth perusing.
http://www.cryptopp.com/
might be a good library.
It was used in this speed test:
http://www.cryptopp.com/benchmarks.html
Unfortunately there is no comparison with OpenSSL available

Categories