Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all 1710 articles
Browse latest View live

Create p7m envelope

$
0
0

Hi all, this is my first attempt at using pkcs classes to create a p7m envelope.I am trying to accomplish the following

1. sign a document with a certificate

2. envelope the signed document in a p7m file that is viewable using p7mViewer or SignoReader

What I want is a valid p7m file with NO recipients, that is I do not intend to send the file to anyone, but only store the signed file in a DB.

I create a SignedCms, pass my document byte array to a ContentInfo instance, compute the signature, Encode() and then save all as .txt.p7m but Signoreader does not recognize the file format.

Anyone already worked on a similar issue?

Thanks in advance,

Luca


Problem while opening VS 2010

$
0
0

When i try to open the VS 2010 the following error comes and request some solutions on this

Microsoft Visual Studio has encountered a problem and needs to be closed

Problem signature:
  Problem Event Name:    CLR20r3
  Problem Signature 01:    devenv.exe
  Problem Signature 02:    10.0.30319.1
  Problem Signature 03:    4ba1fab3
  Problem Signature 04:    PresentationCore
  Problem Signature 05:    4.0.0.0
  Problem Signature 06:    4ba1f865
  Problem Signature 07:    533f
  Problem Signature 08:    11
  Problem Signature 09:    System.IO.FileNotFoundException
  OS Version:    6.1.7600.2.0.0.256.48
  Locale ID:    1033

Additional information about the problem:
  LCID:    1033


How to generate a mixed model C++ .NET DLL with CLR option using AFX library?

$
0
0
I am trying to create a mixed mode (managed and unmanaged) C++ DLL with CLR option and I require the use of AFX library. So I included "afxwin.h" in a file (which uses GL/gl.h). However I run into compile errors no matter what I do and I have tried every option in the project settings to fix them, but no use.

A. When I compile with CLR option I see this error:

1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(24): fatal error C1189: #error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

B. When I compile with _AFXDLL defined in stdafx.cpp or enabling "Use MFC in a shared DLL" I see these and whole bunch of other errors in the same file: 

1>  _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(46): error C2059: syntax error : '-'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60): error C2143: syntax error : missing ';' before '}'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60): error C2238: unexpected token(s) preceding ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(61): error C2059: syntax error : 'public'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2589: '-' : illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2059: syntax error : '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(67): error C2143: syntax error : missing ';' before '{'

Any idea how to fix this issue? I am using VS 2010.

Assembly.CreateInstance returns null after merging assembly using ILMerge

$
0
0

Hi,

I am merging two assemblies which are almost same. that is i have an assembly say xyz.dll and i am renaming this to xyzclone.dll. Now iam merging these two(original and renamed assemblies) using ILMerge and output file is xyzclone. Since both the assemblies contain same info i am using the option /allowdup.so all the type names in the output xyzclone is changed. 

After loading the assembly which i got from ILmerge, the create instance returns null. when i get the exportedtype for that assembly the type exists. But when i use the same type to create instance it is returning null

Note: I am merging the original and renamed dlls as i couldnt find any other method to change the assmbly name of a dll.

Please help

How do we change SQL Settings when using the CLR?

$
0
0
At some point our CLR build failed to deploy. Researching it, it is because we are using indexed columns and need to set

CONCAT_NULL_YIELDS_NULL

to on.  Opening up a brand new project and deploying fails for the same reason.  The first thing the deployment script runs is this:

GO

SET

ANSI_NULLS,ANSI_PADDING,ANSI_WARNINGS,ARITHABORT,QUOTED_IDENTIFIERON;

SET

CONCAT_NULL_YIELDS_NULL,NUMERIC_ROUNDABORTOFF;

How do we alter these settings using the Visual C# SQL CLR Project?  Picking other server type projects these settings are available to change, but in 3 days of searching the net and trying to alter this, I haven't been able to come up with anything.  I can open the script file Visual Studio creates and manually change this and import our CLR, but this basically stops me from being able to debug the clr as the first thing VS tries to do when you go to debug the project is to build and deploy it (which fails).

TLBEXP warning about IPictureDisp

$
0
0

Hi,

I'm working on a C# library that is to be used as a COM component. A Picture property of type IPictureDisp is exposed.

During TLBEXP I get the warning message "TlbExp : warning TX0013116F: Type library exporter warning processing 'Easymap.AddIn.COM.IImageElement.get_Picture(#0), Easymap.AddIn'. Warning: Type library exporter could not find the type library for 'stdole.IPictureDisp'.  IUnknown was substituted for the interface."

My project has a reference to stdole.dll and the exported typelib has an importlib("stdole2.tlb") statement as well. Everything works but my interface is not strongly typed. So the corresponding typelib seems to be there but the warning comes nevertheless.

Does anyone have an explanation/resolution for this?

Thanks,
Thomas

System.Security.SecurityException: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

$
0
0

Hello.

I'm working on a website that uses a access backend DB. The code runs fine when I debug the site on Visual Studio.

But when i upload it on hosting site,it throws the following exception.

HOSTING: GoDaddy

Here's the stack trace.

Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 


[No relevant source lines]

Source File: App_Web_4wgqvwcx.0.cs    Line: 0 

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessSecurityEngine.Check(PermissionSet permSet, StackCrawlMark& stackMark) +31
   System.Security.PermissionSet.Demand() +68
   System.Data.Common.DbConnectionOptions.DemandPermission() +40
   System.Data.OleDb.OleDbConnection.PermissionDemand() +47
   System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection) +20
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +16
   System.Data.OleDb.OleDbConnection.Open() +43
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +316
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1482
   System.Web.UI.WebControls.AccessDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +62
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
   System.Web.UI.Page.ProcessRequest() +72
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +58
   ASP.results_aspx.ProcessRequest(HttpContext context) in App_Web_4wgqvwcx.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18056

CLR Profiling API problem: IL rewriting issue "System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances"

$
0
0

Failure details: System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
   at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
   at com.altaworks.da.DsaPortRequestor.getPortUsingSocket(String hostName, Int32 httpPort)

This problem seems to match another blog posting on the Microsoft Forums and in that case a profiler was in the picture as well. The suggestion there was to turn off legacy code access security. Turning off legacy code access security ("LegacyCASModel=false") will fix the issue but that is not an acceptable solution.

The application profiled is a SharePoint 2013 application. Through IL rewriting the profiler is adding an assembly reference to an external helper assembly that is associated with the unmanaged profiler. That assembly is being loaded into the shared app domain apparently with Full Trust and in a Security Transparent manner. The problem was reproduced on Windows 7 but was first reported on W2k12-R1 and W2K12-R2. 

The helper assembly is attempting to send profiling data collected to another process.

Security Rule Set: Level1
Is Fully Trusted: True
Zone Evidence: MyComputer
Security Critical: False
Security SafeCritical: False
Security Transparent: True
Operating System: Windows 7 (Microsoft Windows NT 6.2.9200.0)
OS Version: 6.2.9200.0
.NET Version: 4.0.30319.18046
CLR running in: 64 bit mode


How do I monitor memory usage of AppDomains in my Process hosted in a Windows Service?

$
0
0

Hello,

We have a Windows Service (or a console) that hosts multiple AppDomains.  We would like to monitor the memory usage of each AppDomain.  The Process is of .NET 4.5, is hosted on Windows 7, and is being developed with VS 2013 in C#.

The example we used came from: http://msdn.microsoft.com/en-us/library/system.appdomain.monitoringsurvivedmemorysize(v=vs.100).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

However we noticed the memory values reported are way too low, and suspected that they are being updated even after Gen0, Gen1, and non-blocking Gen2 garbage collection.  We expect memory update only after a full and blocking GC collection.

This is the same issue reported few years ago without a workaround in the thread: https://connect.microsoft.com/VisualStudio/feedback/details/765296/appdomain-monitoringsurvivedmemorysize-property-returns-wrong-value-after-gen-0-collection#tabs

In addition, we have tried to implement a solution which handles full GC collection without much success: http://msdn.microsoft.com/en-us/library/system.gc.registerforfullgcnotification(v=vs.110).aspx In this exercise, we were able to capture the real memory usages of the first few AppDomains before they are reset again by other GC collections.

Does anyone else have the same experience and is able to provide a workaround?

Thanks,

Jerry

Is there a reason we should not develop without any strong naming and perform it before publishing?

$
0
0

Hello,

It was recommended this forum is better to ask about setting up the team development process (using VS & TFS) regarding signing an application for deployment.  If that is incorrect, please advise.

My question regard developing a windows forms application for public use, deployed for download from a website.

Regarding strong naming, is there a reason strong naming should always be done during development?  In other words, why not develop freely without all the work-around techniques for file/assembly verification, and then strong name during the final build before deployment?  In other words, not even use delay sign during development.

What might some situations be where it would be OK to not strong name during development and leave it until the end?

Best Regards,

Alan

Debugging custom profiler

$
0
0
Is WinDbg the only tool I can use or can I put a debug break in the C++ code and attach via Visual Studio?

Assembly.Load(byte[]) and XmlSerializer InvalidOperationException

$
0
0

Hello,

I can't figure out what makes XmlSerializer of a type loaded by Assembly.Load(byte[]) in AssemblyResolve event handler go InvalidOperationException in Serialize or Deserialize?!

Why, if:

1. Assembly.Load(byte[]) loads the assembly without a load context(LoadNeither)?

2. XmlSerializer loads the generated assembly using the same Assembly.Load(byte[]) overload?

Why is there an InvalidOperationException then when casting from one type to another from the same assembly(serialized types)?! All assemblies should be loaded without the load context.

Then, if I use Assembly.LoadFile instead of Load(byte[]) at the same point it works fine without the IOE!? It should be loaded without the context too or am I wrong?(obviously I am)

If I make the assembly available to fusion in the probing path it loads(load context) and it also works. Default behaviour. 

Is Incremental Backup with VSS possible without Backup Stamps?

$
0
0

i'm trying to do a little backup app that needs to comunicate with VSS Writers and do an incremental backup.

After some reading i now know that there are a few possibilities to do incremental:

  • with partial files
  • with list of files changed since last backup

More info HERE

This makes sense, but the writer i'm querying returns those 2 lists empty. Still makes sense because i gave no backup stamps to my writer.

The real problem is that even after a successful backup the Writer i'm using always gives null on GetBackupStamp value. I set every component on success and completed the backup, looks like VSS is perfectly fine with my backup except for the missing Backup Stamp.

Every file to backup have those flags (more info HERE):

  • VSS_FSBT_FULL_BACKUP_REQUIRED
  • VSS_FSBT_INCREMENTAL_BACKUP_REQUIRED
  • VSS_FSBT_FULL_SNAPSHOT_REQUIRED
  • VSS_FSBT_INCREMENTAL_SNAPSHOT_REQUIRED

This happen because i don't have a way to tell VSS Writer about my initial Full Backup (i have no backup stamp!).

If i try to set my backup as Incremental (since its supported by this Writer, i have the Incremental Flag in writer metadata) it fails at PrepareForBackup(), i still think because i did not set a backup stamp or some refeerement to the first Full Backup. I check this error in the Writer State, i have the flag VSS_WS_FAILED_AT_PREPARE_BACKUP (more info: HERE)

TL;DR

And this brings me here, with this question: What i'm missing? There is some other way beside using Backup Stamps to do Incremental Backup with VSS?

COM interop assemblies and PrimaryInteropAssemblyCodeBase

$
0
0

We have a pretty big issue with registering 32-bit and 64-bit primary interop assemblies and maintaining IntelliSense support. We ship both 32-bit and 64-bit COM in-proc servers and register the corresponding 32-bit and 64-bit PIAs.  We use the PrimaryInteropAssemblyCodeBase value in the TypeLib entry to point to the location of our PIAs on disk.  This PrimaryInteropAssemblyCodeBase value is required to get Visual Studio to locate the XML IntelliSense file for rendering IntelliSense for that PIA -- you point the code base at the DLL and put the XML file next to it and Visual Studio renders the content.

The problem is that with Windows 7, the TypeLib section of the registry is shared, so you can only point PrimaryInteropAssemblyCodeBase at either the 32-bit or 64-bit PIA (not both).  If you point it at the 32-bit PIA, then building 64-bit apps using that PIA fails in Visual Studio (and vice-versa if you use the 64-bit PIA location).  If you don't use the PrimaryInteropAssemblyCodeBase value at all, then Visual Studio will resolve to the correct PIA via the GAC and builds work -- but IntelliSense is *not* rendered because the XML IntelliSense file obviously is not (typically) installed in the GAC.

Building the PIAs as "Any CPU" does work, but it feels "wrong" since PIAs *really* are, by definition, bitness-dependent.  This seems fundamentally broken and I'm wondering how others have not come across this.

Any help or insights are much appreciated.


Kirk Fertitta

why does .net suck at simple math???

$
0
0

take the simple subtraction 43.709719 - 43.7097189

which should yield 0.0000001, however when i type in that problem into the watch bar(or have a pair of values with sufficient precision i get a result like this:

WTF?!?!?!

how am I supposed to build a program that will handle high precision values if the language compiler can't even handle subtraction!  both visual studio 2010 and 2012 show this inability to handle subtraction of precision numbers

while i know for this example i could use a decimal declaration to handle them since both have fewer than 8 decimal places, i have values that are accurate to 14 decimal places that i need to work with.

Edit:

also trying things of a lower precision... from Watch 1

        1.0 - 0.9    0.099999999999999978    Double


Timer components

$
0
0

am trying to develop certification record system by C#, access database and i want to know about Timer, here is the problem:- when a customer come to our office and register his/her company, the company name will be registered as new on our system, every year the company certificat has to be renewal and to renew our stuff mebers go on site and check wither there working properly or not ..... so i want my system to count starting form the registeration of the company to 12 month and give them some notification;

can this be done with Timer???

Thank You for your help. 

C# - reading and writing memory for game trainer

$
0
0
I'm interested in creating a small trainer for a single player game I made and want to know how to read/write memory with C# given a specific memory address.

I found the memory addresses which hold the score (int '004F19EC') and player x position (float '01150630') and want to use them to produce variables in C# to track them and manipulate them.

I couldn't find much info on how to do this. It seems I use the Marshal class but I'm having trouble figuring it out. If someone could show a sample of how this is done, I'd appreciate it.

Determine FIPS Algorithm Policy seting in use NOT the registry value

$
0
0

Is there a way to check if a user is allowed to use non FIPS 140-2 security algorithms

I know you can look at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy and it MIGHT give you the correct answer.

However checking this value doesn't really tell you anything other than what is currently set in the registry; NOT what is currently allowed. 

That is the user can change this after startup, however, I believe Windows checks the value at startup, so if it was changed after startup or if the value was changed by an OU policy after the windows set the value (wherever and whenever it sets the value), then the value in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy does not give you the value that is currently in affect.

The reason I am asking is I have the setting set to 0, but I still get:

  RijndaelManaged CSP = new RijndaelManaged();

System.Exception : Error in RijndaelAES encryption: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
  ----> System.InvalidOperationException : This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

I'm thinking some domain OU policies are messing with this during startup.

I also know that if you have a web application, that in the web.config you can:

  <runtime>    <enforceFIPSPolicy enabled="false" />  </runtime>

This is not set to true.

So it would be nice to see what the OS thinks can be used and what the .net framework thinks can be used.


hooking SetErrorInfo of managed COM object from unmanged code does no longer work since CLR4.0

$
0
0

Hi,

for .Net 3.5 we created a hook into SetErrorInfo to get additional information of manged COM objects like the callstack.
We implemented the hook like desscribed in this article: http://msdn.microsoft.com/en-us/magazine/cc188710.aspx

But since we need to use .Net 4.0 for our assemblies the hook no longer works. As soon as an exception occurs in the manged COM object we get an access violation to addresses outside of our unmanged programm.

Any ideas how to fix this? Does CLR4 no longer call SetErrorInfo for exceptions?


Best regards,
 
Harald Binkle


Exchange Server Toolbox |SmartPOP2Exchange | SpamAssassin
JAM Software GmbH
Am Wissenschaftspark.26 * 54296 Trier * Germany
http://www.jam-software.com


AppDomain.CurrentDomain.UnhandledException not fired in COM object

$
0
0

Hi,

I have a simple mange COM object (.Net4.0) providing tow methods: Init() and ThrowTestException()
The init method simply assignes the eventhandler to AppDomain.CurrentDomain.UnhandledException.
The ThrowTestException throws an exception.

Then I instantiate this COM exposed class from unmanged code and call Init().
This works fine, as I can see in stepping throw using VS as debugger.
But when calling ThrowTestException() afterwards the handler is NOT called. I directly get an OleException in my unmangde code.

Why does AppDomain.CurrentDomain.UnhandledException not fire?


Best regards,
 
Harald Binkle


Exchange Server Toolbox |SmartPOP2Exchange | SpamAssassin
JAM Software GmbH
Am Wissenschaftspark.26 * 54296 Trier * Germany
http://www.jam-software.com

Viewing all 1710 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>