Access Denied VS 2010 - c#

i m trying to build COM dll file using C# and VS2010 - framework 3.5-:
if i try building the project without performing Clean, it will build, however this works only before any cleaning operation, after cleaning the project i will get stuck with this error
Error 16 Cannot register assembly "C:\Users\User\Desktop\Demo[Demo]
SCPP T1\bin\Debug\PrinterPlugin.dll" - access denied. Please make sure
you're running the application as administrator. Access to the
registry key
'HKEY_CLASSES_ROOT\CLSID{B9162A23-45F9-47CC-80F5-FE0FE9B9E1A2}' is
denied. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 3912 5 PrinterPlugin
i have based the original files on FrameWork 4.0 then converted to 3.5 due to COM registration incompatibility. building with Framework 4.0 will build successfully but will produce "TYPELIB" file is missing while registering the library.
further elaboration, the old PrinterPlugin works like a charm based on framework 3.5, it would register correctly, and would function with no warnings or erros of what-so-ever, these errors started popping after adding some components from another SDK that have been distributed using framework 4.0 and uses other microsoft libraries, like bidispl.dll, ReachFramework... etc.
EDIT0
i already have tried starting the VS2010 as admin, from every location.
EDIT1
i have tried building a new project using Framework 3.5, and still facing the same error, even when executing the devenv.exe as admin from the Common7 > IDE folder.
Error 18 Cannot register assembly
"C:\Users\Ameer\Desktop\projects\PrinterPlugin without resize
17-05-2015\printerplugin without resize
10-05-2015\bin\Debug\PrinterPlugin.dll" - access denied.
Please make sure you're running the application as administrator.
Access to the registry key
'HKEY_CLASSES_ROOT\CLSID{B9162A23-45F9-47CC-80F5-FE0FE9B9E1A2}' is
denied. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 3912 5 PrinterPlugin
i m guessing this is something has to do with the compatibility between the two SDKs.

Related

Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155

I'm having an issue with a very simple piece of C# .NET code which should (for now) simply retrieve the version number of Office installed on the computer running a WinForms application:
var oApp = new Outlook.ApplicationClass();
var outlookVersionString = oApp.Version;
It instantiates the object correct, however when I try and access the Version property, I get the following:
{"Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155)."}
I've done a lot of searching online, so a run-through of what I've tried:
Checking that in [HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}] only one Key exists (9.6)
Checking that this ClassID and version matches in [HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
Registering MSOUTL.OLB with C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regtlibv12.exe "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because regtlibv12.exe isn't shipped with VS2017)
Downloading regtlibv12.exe and trying again (fails because 'This app can't run on your PC').
Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
Using what worked with the old Interop libraries (edit: note, this does not appear to work with our Office 2016 desktops), which is a subtle change:
var oApp = new Outlook.Application();
var outlookVersionString = oApp.Version;
It might be worth noting that I have a clean Windows 10 Enterprise N Creators Update, and Office 2016 / 365 ProPlus, haven't had any previous versions installed, and haven't downgraded.
I'm not normally a desktop app developer so while I grasp some of these library registration tools, I'm by no means an expert..
Try to "repair" your Microsoft Office installation. Go to Programs and Features, select Modify and then Repair Online. I had the same issue and this fixed it.
Some my customers had a similar issues on some PC and the only action that have solved was usign the point 3 "Ensure MSOUTL.LIB is Registered" of this fantastic guide webmakers - Interface not registered (Exception from HRESULT: 0x80040155) – Microsoft Office/Outlook Error, after checked the previous point, obviously.
Thanks to Jatin-Auckland for a clear and step by step guide.
Goodluck ;)
I appreciate this is an old topic, my issue was Visual Studio defaulting to 'Prefer 32-bit' in the project's compile properties for .NET Framework 4.5+. !
Screenshot of Visual Studio Prefer 32-bit checkbox:

.NET executables do not work after overwritten with new versions

I faced very strange behaviour - after I overwrite .NET exectables with new versions from network drive it cannot start.
When try to start from Windows Explorer it shows me following error:
[Window Title]
C:\Programs\zzz\clients.net\zzzNet.exe
[Content]
C:\Programs\zzz\clients.net\zzzNet.exe
The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
I tried to execute following commands:
SxsTrace Trace -logfile:SxsTrace.etl
SxStrace Parse -logfile:SxSTrace.etl -outfile:SxSTrace.txt
And got following result:
=================
Begin Activation Context Generation.
Input Parameter:
Flags = 0
ProcessorArchitecture = AMD64
CultureFallBacks = en-US;en;ru-RU;ru
ManifestPath = C:\Programs\zzz\clients.net\zzzNet.exe
AssemblyDirectory = C:\Programs\zzz\clients.net\
Application Config File = C:\Programs\zzz\clients.net\zzzNet.exe.Config
-----------------
INFO: Parsing Application Config File C:\Programs\zzz\clients.net\zzzNet.exe.Config.
INFO: Parsing Manifest File C:\Programs\zzz\clients.net\zzzNet.exe.
INFO: Manifest Definition Identity is (null).
ERROR: Line 0: XML Syntax error.
ERROR: Activation Context generation failed.
End Activation Context Generation.
It is quite simple .NET application (1 exe + 8 dll files). It was built for .NET 3.5 Client Profile.
I not defined any special "manifest" there. Just clicked "New Windows Forms Project" in Visual Studio and developed it.
Also app.config does not contain anything special - only primitive standard settings - appSettings and userSettings sections.
On PC where I developed it all is perfectly works. Problems only began when I copy these binaries to this particular VM and try to start.
Also please note - these executables were not installed in GAC or such, I just copied them into a folder on VM and started. And when it was 1st time all was working fine.
So, the problem pattern is following:
Copy .NET execuatbles to new VM (it is Win 7 x64), run it, all is working fine. Close it.
Build new version of .NET execuatbles on host PC, copy new .NET execuatbles to VM (with files overwriting).
Try to start - got mentioned problem.
After some shaman-style actions (like OS reboot, etc) it begin to work but why that happened at all?!
Why replacing .NET executables with new versions is causing SUCH HUGE PROBLEMS?!
Also the BIG QUESTION - is there any special procedure to replace .NET executables to keep them working? Because it is a new app development, I do not want lost so much time on every new executables installation. :-\
Could you please help? Because it looks completely weird!
Thank you in adance.
PS. I checked all VS projects - all they have PlatformTarget=AnyCPU. Also in run-time I can see ProcessType=MSIL (I show this info in AboutBox for application). So, there is no mix of x86/x64 binaries.
It seems that was related to mapped network drive behavior.
When I copied new files from network drive folder it copied wrong files - a strange random mess of new files and older ones (which were there before I updated them on VM host).
The scenario to make it working:
on VM: delete all files in a folder on network drive
on VM host: copy new files into a folder which is mapped as network drive on VM
on VM: copy files into target folder
on VM: run application - it works now
Weird thing. I remember I have seen something similar with Windows Explorer on Windows 2008 behaviour when copying updated win32 binaries.

Windows store app fails AppContainerCheck

I'm getting the below error when I try to run the app certification test on my windows 8.1 app. I've looked around for a while and can't seem to find any solutions for this. The app is written in C#/xaml which I wasn't aware even had a linker.
I'm hoping that someone can guide me in the right direction on how I should start to investigate an error like this as web searches have thus far failed me
Binary analyzer
•Error Found: The binary analyzer test detected the following errors:
◦File [MyTabletApplication.exe] has failed the AppContainerCheck check.
•Impact if not fixed: If the app doesn’t use the available Windows protections, it can increase the vulnerability of the customer's computer to malware.
•How to fix: Apply the required linker options - SAFESEH, DYNAMICBASE, NXCOMPAT, and APPCONTAINER - when you link the app. See links below for more information:
If you are using Visual Studio 2015 and this is a new solution/project make sure the 'Compile with .NET Native tool chain' check box is cleared in the startup project properties in the Release configuration.

Class not registered error from PHP

We've created a C# class library assembly and made it COM visible to be able to call its methods from PHP. This used to work fine, but now we wanted to install it on a Windows Server 2008 server and we keep walking into the error "Class not registered".
To rule out any dependency problems I made a tiny little test class library in C#. The class library is built for Any CPU and it is COM visible (also set COMVisible to true in AssemblyInfo.cs). The test class library only contains one class with one method. The class is called TestLib and the namespace is also called TestLib. The method is called Test and only returns a string.
What we have done is the following:
- built the TestLib.dll
- copied it to the Windows Server 2008 machine
- registered the dll with: regasm /codebase TestLib.dll
- the regasm tool returns a success message
- in PHP we simply try to create a new COM instance:
try
{
$test = new COM("TestLib.TestLib");
}
catch (Exception $e)
{
die($e->getMessage());
}
when we call this test script from either the browser or the commandline (php -f test.php) we get the error "Class not registered" in both cases
I also tried adding TestLib to the GAC by using gacutil -i, but to no avail; still the class not registered error.
Then I tried compiling the testlibrary with .NET 2.0 instead of 4.0 as the target framework, same result. The .NET framework 4.0 is installed on the server by the way.
Any ideas?
Okay, so after some more research I figured it out. The php.exe process is 32 bit. The COM visible assembly is compiled for Any CPU so it should be accessible to both 32 and 64 bit applications.
The problem is that on a 64 bit OS php.exe, and any 32 bit process for that matter, searches in HKEY_CLASSES_ROOT\Wow6432Node\CLSID instead of HKEY_CLASSES_ROOT\CLSID and in HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID instead of HKEY_LOCAL_MACHINE\Software\Classes\CLSID. The registry entries in the Wow6432 keys aren't created by regasm that is shipped with .NET framework v4 on Windows Server 2008. On Windows 7 they are created, don't ask me why.
It also turned out that if I create a little test assembly for .NET v2.0 and register it with regasm that ships with .NET framework v2.0 that it does create the Wow6432Node entries on Windows 2008. Strange.
So my solution is to create a basic registry file on the server using:
regasm /regfile MyClassLib.dll
This creates a file MyClassLib.reg with only the 'normal' 64 bit entries. Then I exported the Wow6432Node keys from a Windows 7 machine and added it to that .reg file. Now when I import that reg file into the registry on Windows 2008 everything works fine.
For more info on the Wow6432Node entries check out: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072%28v=vs.85%29.aspx
Hope this saves someone else some time and headaches.
If you are trying to call a 32-bit COM DLL on 64-bit Windows, you will need to register it.
Copy your 32-bit DLL to C:\Windows\sysWOW64
Run C:\Windows\sysWOW64\regsvr32.exe your_com_32.dll
A bit more info with screenshots.

c# OPC Automation gives 80040154

I am a .Net developer. New to OPC. When I tried some samples of OPC Client all of them give this error. It seems the DLL is not registered it seems. But I don't know how and where to register this.
error: retrieving the COM class factory for component with CLSID failed due to the following error: 80040154
Even I tried this
regsvr32 Interop.OPCAutomation.dll",
but it also throws error like
The module "Interop.OPCAutomation.dll" was loaded but the entry-point DllRegisterServeer was not found.
Make sure that "Interop.OPCAutomation.dll" is a valid DLL or OCX file and then try again.
I have gone through so many existing forums. So many of them said to change the Platform Target to x86 and still I am having the same issue. FYI, I can see only see 'Active (Any CPU)' in the Platform option from the top of the Build tab of Project Properties.
Here are my environment details:
.Net 2005
OPCAutomation Weapper
Windows 7 64-bit OS
Dell Inspiron 1525 (I hope this is not a 64bit machine, but my engineer installed 64bit OS somehow).
Please help me.
Thanks in advance!
Just in case somebody is dealing with this problem (as I've recently been...) I get through it! After some time, I found out that it's something about the .NET framework running on 64-bit machines. As long as the.NET application works only with 32-bit CLR, we must set .NET framework to load CLR in WOW mode. To do so, type:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow
After this you should be able to run the applications.
You can go back and revert .NET Framework as it was before by typing:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64
If the OPC Client Toolkit SDK (C++) is used, a problem with the remote registry service may cause this error as well.
On Windows 7, by default the Remote Registry service is set to manual and not started. Ensure that the Remote Registry service is started on all of the machines you want to deploy to. This can be done manually or using Group Policy.
The function GetCLSIDFromRemoteRegistry() uses the RemoteRegistryService in order to get the CLSID of an OPC Server. If this service is not started on the client machine, the OPC program may return the error 80040154.
The error you're getting is more than likely due to the OPC server not being properly registered. Make sure it is registered (usually by running it at the command line with a "/regserver" or "/service" parameter). There may also be security issues in which case you'd have to run 'dcomcnfg' (DCOM Config) to make sure the client has access to the server.
This question is a bit dated so I hope you figured it out by now, but I had the same exact issue and wanted to share my solution. In my case, I am using a Kepware server. If you compile and try to run a client application for this server using Interop.OPCAutomation on a machine that does not have the server installed, you will get a dll not registered error and "entry point not found" if you try to register the dll manually.
Solution: Make sure you've got the server installed and running.
Although this is an old post, I would like to share my solution.
My problem was that when I tried to install an application with the OPCAutomation.dll, it gave me 80040154 error because the class was not registered.
This is my solution, always with Administrator privileges:
Copy OPCDAAuto.dll into the "C:\Windows\System32" folder
On the cmd prompt type "C:\Windows\System32\regsvr32 opcdaauto.dll"
You should watch a message like this one:
image
Hope this helps!
The OPC dll only works in 32 Bits, my solution was to change the "Enable 32-Bit Applications" to True in the advanced settings of the relative app pool in IIS.

Categories