.net-4.0

How to return KB, MB and GB from Bytes using a public function

巧了我就是萌 提交于 2019-12-04 13:16:28
问题 I'm writing a "function" that returns a file's size (in B, KB, MB, GB). The VB.Net code always gets the size in bytes first, so when a file's size (in Bytes) is less than 100 it returns B, if its > 1000 then I divide it by 1000 and it returns KB. But when it should be MB I try dividing by 1000000 and the size it returns always comes out 2 MBs bigger than what it should be!? Can someone please tell me what I'm doing wrong!! Example My files size is (15,570,550 Bytes) ..which is.. (14.8 MB) So

Produce a .NET 4.0 library from a PCL Project where code is identical

懵懂的女人 提交于 2019-12-04 13:12:26
It's quite frustrating, I have a Portable Class Library (PCL) library that had to drop .NET 4.0 in the profile to have access to the right API's "in PCL land". However, these API's do exist in .NET 4.0, such that if the exact same code is in a .NET 4.0 project it compiles just fine. I want a minimal ongoing maintenance way to recompile the code in this PCL project to .net 4.0 so I can include it in a Nuget package. With minimal conditional adjustments to the .csproj , an msbuild project can be created to compile a portable library solution to produce additional .net 4.0 profile binaries. Build

log4net and .net Framework 4.0

孤街浪徒 提交于 2019-12-04 13:04:35
I was having issues in log4net when I updated my solutions to .net 4.0 , and then I downloaded the source of it and built log4net and targeted it to .net 4.0 and used it in my projects. Initially when I referred log4net that is targeted to run time 2.0 it complied and run the application but log did not work. Now when I run my project with log4net targeted to .net 4.0 I get the error "The type initializer for 'Log4NetTest.TestLog' threw an exception." Any Idea how to solve this? Edit: this is the inner exception: InnerException: System.TypeLoadException Message=Inheritance security rules

Silverlight 4 Assembly Sharing Problem

跟風遠走 提交于 2019-12-04 12:56:46
I have a WPF .NET 4.0 class library referencing a Silverlight 4 class library. The SL library compiles fine but when I compile the WPF class library, I get: Error 2 Unknown build error, 'Cannot resolve dependency to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' MyProj.Presentation.Wpf I figure the problem must be similar to the one mentioned here: http://markti.spaces

How to integrate WebSockets on top of a classic ASP web application?

一个人想着一个人 提交于 2019-12-04 12:35:39
问题 In one of my projects, I have a very active classic ASP site with a requirement to integrate live event-based feeds as part of the existing UI. There is a plan to upgrade the site architecture to either MVC or MVP in the future, but this new feature must be implemented in the meanwhile. I have decided to go with a WebSocket approach for this, as this is ultimately what we will want to use in the future, and rebuilding this doesn't make sense. The question is, how to integrate this with the

XmlSerializer vs DataContractSerializer

[亡魂溺海] 提交于 2019-12-04 12:13:33
I just realized that DataContractSerializer expects nodes in the alphabetical order or the specified order. Is there any way i could make it NOT do it? TIA kbrimington I don't think so. You may find the discussion on this question informative: Ignore field order in DataContractSerializer I used IDispatchMessageInspector.AfterReceiveRequest to intercept the message and sort it alphabetically. 来源: https://stackoverflow.com/questions/3570729/xmlserializer-vs-datacontractserializer

Parallel For Loop - Problems when adding to a List

雨燕双飞 提交于 2019-12-04 12:01:28
问题 I am having some issues involving Parallel for loops and adding to a List. The problem is, the same code may generate different output at different times. I have set up some test code below. In this code, I create a List of 10,000 int values. 1/10th of the values will be 0, 1/10th of the values will be 1, all the way up to 1/10th of the values being 9. After setting up this List, I setup a Parallel for loop that iterates through the list. If the current number is 0, I add a value to a new

How to connect to a running instance of outlook from C# [duplicate]

好久不见. 提交于 2019-12-04 11:46:03
This question already has answers here : Getting/Creating an Outlook Application in Windows 7 (5 answers) Closed 5 years ago . In VBA, I usually use appOutlook = GetObject(, "Outlook.Application") to get a running instance of Outlook, and it throws an error if Outlook isn't running. I normally did this in excel, but now I am wanting to see if I can get better results by moving to C# and doing it from there. What I need to do is copy emails from outlook and paste them into excel so that the tables in the email get pasted into the spreadsheet as cell values rather than html. However, I'm not

How to set a binary attribute when using a AccountManagement Extension Class?

情到浓时终转凉″ 提交于 2019-12-04 11:45:54
I am using a custom class to expose some custom schema in Active Directory . I am storing a binary blob, per the project requirements this data must be stored in the AD, I can not use a external store (I would if I could). When I create the user it stores the blob fine. I also can retrieve the blob back out fine too and get all my data. The issue is if I need to update the value and I am getting errors Small example program: using System; using System.DirectoryServices.AccountManagement; namespace SandboxConsole40 { class Program { static void Main(string[] args) { using(var context = new

How to handle report viewer session expired exception

ぐ巨炮叔叔 提交于 2019-12-04 11:41:06
I have the following situation: Microsoft Report Viewer 2010 is used to display reports (.rdlc files) in local mode in an ASP.NET web application. The report data is supplied by assigning a datasource in the code behind of an ASPX page. Here's an example: if(!IsPostBack){ ReportViewer1.Reset(); ReportDataSource reportDataSource = new ReportDataSource(); reportDataSource.Name = "DataContainerType"; reportDataSource.Value = DatasourceOnPage; reportDataSource.DataSourceId = "DatasourceOnPageID"; reportDataSource.DataMember = "DataSourceView"; ReportViewer1.ProcessingMode = ProcessingMode.Local;