Read Email in VB.NET / ASP.NET - asp.net

UPDATE
Now, after trying to use EWS as an alternative I've been getting this new error message that I can't seem to fix :
DTD is prohibited in this XML document.
And yes I've given these code a try :
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.XmlResolver = Nothing
settings.DtdProcessing = DtdProcessing.Parse
settings.ValidationType = ValidationType.DTD
Dim reader As XmlReader = XmlReader.Create(".xml", settings)
But it made no difference. Please Help!!
For your information : I'm trying to make this to run in a web based version
My code works perfectly during execution to read email using VB.NET.
Unfortunately this happen :
"Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Additional Info:
I'm a company worker = email I want to retrieve is using company
domain (eg: ...#company.com)
Windows 10
Microsoft Outlook 2016
Visual Studio 2012
.NET framework 4.5.1 & 4.5.2
I code it using Microsoft.Office.Interop
I've searched google for solution on how to handle the problem and so far no luck.
I've tried modifying DCOM
I want to download new security update from support.microsoft, but no luck with the company internet restriction
Please help. I've been stuck for almost a month on this problem

Most likely this happens if Outlook and your app are running in different security contexts (e.g. one app is running as an admin). Try to close Outlook before starting your app - if that works, you have mismatched security context.
Also keep in mind that Office apps (including Outlook) cannot run in a service (such as IIS).

Related

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

im trying to add a default user admin in an .net application while the application is launched (code in startup.cs) but i got this error .
i was following this tuto
https://www.c-sharpcorner.com/UploadFile/asmabegam/Asp-Net-mvc-5-security-and-creating-user-role/
enter image description here
here the function of creating new default user .
enter image description here
I am using Visual Studio 2015 with SQL Server 2017 Express LocalDB on this Windows 10 (64-bit) machine.
You're using a different context than what that example has (ReportContext instead of ApplicationDbContext). Where is ReportContext defined? I don't see a built-in class for it, so I'm guessing that's custom code.
Also, it's generally better to post code as text than images, since it makes it easier to follow the flow and keeps the relevant bits of the question self-contained.

Error coming up when trying to open up file browser

Currently on my website i am trying to get it so that a user can upload an image from their local images. I have followed a tutorial, but when i debug it and try to open up my images folder i get this error message:
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
Please can someone help me here, i have read a few posts; but seen as this is my first time doing this; i dont really understand them.
Thanks for any response!
You are trying to use Windows Forms functionality in a ASP.NET Web Page. Line 140:
FileDialog fldlg = new OpenFileDialog();
Windows Forms is desktop technology. You can't mix that with a ASP.NET web app. You can use the FileUploadControl to enable file uploads in your web application:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx

Trouble using Epplus and Service.svc

I have a Web Site with an Service.svc file, i created this using the Add New Item -> AJAX-enabled WCF Service, for weeks, everything works fine.
Today, i imported the EPplus.dll to generate some excel files. When i try to compile i get this error
Error 1 Reference.svcmap:
Failed to generate code for the service reference 'QUAY.Tractebel.COP.Servicos'.
Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Type 'OfficeOpenXml.ExcelRangeBase' is a recursive collection data contract which is not supported.
Consider modifying the definition of collection 'OfficeOpenXml.ExcelRangeBase' to remove references to itself.
XPath to Error Source: //wsdl:definitions[#targetNamespace='']/wsdl:portType[#name='Servicos'] App_WebReferences/QUAY/Tractebel/COP/Servicos/
I have no idea how to solve it, someone can help me?
Just had the same problem while referencing a custom wcf class i use.
The strange problem is that on my old development pc (windows vista 32bit, visual studio 2010) i haven't got this problem, it only pops up in my new system (windows 8 64bit).
Bah.
However, i bypassed the problem opening App_WebReferences --> "your service name" --> Right click on depending Refrence icon --> "Configure service reference"
In this screen move the option button from "Reuse types in all referenced assembiles" to "Reuse types in specified assemblies" and check all the depending libraries EXCEPT EPPlus
Compile and ... voila
If someon has also a logic explanation, i'll gladly listen

Exception when using localized resources in Windows Azure

I have been developing an application in classic ASP.NET and deploying it to azure. Until now, no problem at all. Now I want to add localized resources to support multi-language.
The App_GlobalResources/*.resources files works fine when running local, both outside and inside the azure emulator. But when I try to use them in Azure, I'm getting the following error:
Could not find any resources appropriate for the specified culture (or
the neutral culture) on disk. baseName:
SistemaRRHH.Signup.SignupLabels locationInfo: fileName:
SistemaRRHH.Signup.SignupLabels.resources.
The exception is very self-explanatory, buy I can't solve it in any way.
The exception is thrown here:
var requestCultureInfo = new CultureInfo(Utils.GetRequestFirstLanguageAccepted(Request.Headers["Accept-Language"]));
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager(Constants.RESOURCE_FILE_LABELS_NAME, HttpContext.Current.Server.MapPath(Constants.RESOURCE_FILE_DIRECTORY), null);
letsGetItStartedLabel.Text = rm.GetString(Constants.LETS_GET_IT_STARTED_LABEL, requestCultureInfo);
Thanks a lot for your help!
I've noticed some localisation issues within Azure, specifically with DateTimes (the usual culprit) - are you based outside of the US? We're based in the UK and using a European Data Centre but still getting US-formatted dates within Azure. If that is the case, you could try creating en-US resource files as well to see if that fixes the issue. We added a globalization tag into the web.Config for now - a short term fix but gets past the issue until I can revisit.

ASP.NET unit testing Windows7/IIS7

Spent several hours today trying to write some unit tests against an ASP.NET project. It's Visual Studio 2010.
Using Windows 7 Enterprise with IIS7.
Steps I took were:
Added a new test project to the solution
Opened a class file as part of the web site (Member.vb)
Right clicked within the class file and "Generate unit tests"
Select the methods I wish to generate stubs for, choose to add to my test project, click OK
Open up the generated MemberTest.vb file in the test project, click within one of the generated tests, click "Run tests in curent context"
When following these precise steps on my Windows XP Professional with IIS6 machine it works fine.
However on the Windows 7 Enterprise machine on IIS7 I get:
The URL specified ('http://localhost/MyProject') does not
correspond to a valid directory. Tests configured to run in ASP.NET in
IIS require a valid directory to exist for the URL. The URL may be
invalid or may not point to a valid Web application.
So what's going on, I can confirm I can browse to http://localhost/MyProject and it displays perfectly.
I feel sure I'm missing some sort of config in Windows/IIS but I'm really at a loss.
Generated test method:
<TestMethod(), _
HostType("ASP.NET"), _
UrlToTest("http://localhost/MyProject")> _
Public Sub MyMethodTest()
Dim target As Member_Accessor = New Member_Accessor() ' TODO: Initialize to an appropriate value
Dim CurrentVal As Short = 0 ' TODO: Initialize to an appropriate value
Dim expected As Short = 0 ' TODO: Initialize to an appropriate value
Dim actual As Short
actual = target.MyMethod(CurrentVal)
Assert.AreEqual(expected, actual)
Assert.Inconclusive("Verify the correctness of this test method.")
End Sub
(Cross-posted at ASP.NET Forums)
This could be a permissions issue.
If you're using the default directory (C:\users\\Documents\Visual Studio 2010\Projects), the app identity pool does not have permissions there. You'd have to create a project in something like C:\webs and make sure app pool identity has permission to the folder.
Refer to Rick Anderson's blog post at http://blogs.msdn.com/b/rickandy/archive/2011/04/22/test-you-asp-net-mvc-or-webforms-application-on-iis-7-in-30-seconds.aspx and see if that helps.
If you have not done unit testing before, I would really recommend that you start by just testing the functionality of your classes as cleanly as possible. Try to break you you functionality into small pieces that can be tested individually without and dependencies to the web context.
Have a look at this question for an idea about What is unit testing
Here is an MSDN Magazine article about testing
You can also have a look at this Blog. The examples are using NUnit but the principal is the same if you are using MSTest.
I can also recommend Roy Osheroves Book Art of unit testing
In you case if the Member class does not have dependencies to web context you don't need the IIS and could instead just do something like this:
<TestMethod()> _
Public Sub MyMethodTest()
Dim target = New Member()
Dim CurrentVal As Short = 0 ' TODO: Initialize to an appropriate value
Dim expected As Short = 0 ' TODO: Initialize to an appropriate value
Dim actual As Short
actual = member.MyMethod(CurrentVal)
Assert.AreEqual(expected, actual)
End Sub
I ran into the same problem today. After some research, I found this thread which suggested I check my event log. Upon doing that, I discovered numerous errors similar to the following:
(QTAgent32.exe, PID 12348, Thread 61) WebSites.GetWebServer: failed to
create AspNetHelper:
Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The
website metabase contains unexpected information or you do not have
permission to access the metabase. You must be a member of the
Administrators group on the local computer to access the IIS metabase.
Therefore, you cannot create or open a local IIS Web site. If you
have Read, Write, and Modify Permissions for the folder where the
files are located, you can create a file system web site that points
to the folder in order to proceed. --->
System.Runtime.InteropServices.COMException: Unknown error
(0x80005000)
That lead me to this blog post which seems to have resolved the issue.
I just needed to go to "Turn Windows features on or off" and add IIS 6 Management Compatibility and all four subcomponents. I'm running Windows 7 Home Premium which doesn't have the Windows Authentication option, but that didn't seem to be an issue. Give it a shot and see if that resolves the issue for you.
You may need to enable "Use IIS" in the project properties, then click "Create Virtual Directory". Do you have IIS Express installed?

Resources