I start encounter a new runtime System.IO.FileNotFoundException exception after upgrade my system from win7 x64 to win 10 x64.
I have the following code that works perfect until now:
{
PrincipalContext pc = new PrincipalContext(ContextType.Machine, Environment.MachineName);
UserPrincipal usrPrin = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, Username);
if (usrPrin == null) // No user exist
{
return -1;
}
// user exist
return 1;
}
I always built the project using the platform target: x86, when I run the application, I get the exception when call UserPrincipal.FindByIdentity.
A first chance exception of type 'System.IO.FileNotFoundException'
occurred in System.DirectoryServices.dll A first chance exception of
type 'System.IO.FileNotFoundException' occurred in
System.DirectoryServices.AccountManagement.dll
All my projects compile with .net4 and not .net4.5
during my debug now, I find that if I change the build platform target to AnyCPU, the code passed with no issue.
It seems like an OS bug! .Net 4 x86 not installed or something not right!, I tried to reinstall .Net4 but couldn't because it already installed, Iran .net cleanup tool as well.
Any Idea why this exception?
It says the assembly System.DirectoryServices.dll missing. Did you get a chance to verify if the dll is present in your current solution. If not try to download for nuget, build and see. I faced a similar issue and it got resolved with vs 2017 and .net core 2.1 after downloading the System.DirectoryServices dll
Related
I am a beginner in software development. I was following a simple tutorial and was creating a web application in Asp.net MVC - 5. But suddenly my app stopped running even I did not do any fancy stuff. Below is the error I am getting. Please help me here.
Error: System.typeloadexception.
Additional: Microsoft,Ajax.Utilities.OutputVisitor from assembly 'WebGrease'
I have not touched these fancy stuff at all. But as soon as I run the application in local host I start getting this error. Error comes in _Layout.cshtml file near the line
#Scripts.Render("~/bundles/modernizr")
This can happen if your targeted .Net framework version not installed on your System. Check your project properties .Net version and check your Pc has respective .Net installed.
try
{
}
catch (TypeLoadException)
{
// this can happen if respective .Net is not installed in your system
}
TypeLoadException is thrown when the common language runtime cannot
find the assembly, the type within the assembly, or cannot load the
type.
or add this code snippet
AppDomain.CurrentDomain.AsemblyResolve += (s, e) =>
{
return AppDomain.CurrentDomain.GetAssemblies()
.SingleOrDefault(asm => asm.FullName == e.Name);
}
If all attempts fails, try to reinstall WebGrease nugget package
I have a C# program that is using some COM objects available through a tool installed on the machine (Waters Empower 3). Initially when I made the calls I received errors about un-registred classes so I registered the dlls that I am using. Now I get the error below.
System.Runtime.InteropServices.COMException (0x8004020D): Cannot modify or delete an object that was not added using the COM+ Admin SDK (Exception from HRESULT: 0x8004020D)
I'm on a 64 bit windows 7 pro machine. I believe the installed tool is 32bit. I get the error when running the project from VS2013 in 32bit mode.
The exception occurs when I instantiate one of the objects. Specifically
Project proj = new Project();
I'm using the MilTk.dll and MtkCtrl.dll from the Waters Empower toolkit that are registered as COM objects on the system.
The full text of the exception is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in TestResultsExporter2.exe
Additional information: Cannot modify or delete an object that was not added using the COM+ Admin SDK (Exception from HRESULT: 0x8004020D)
I have a situation where I have a windows Desktop APP in .Net C# that must on both Windows 7 and Windows XP rename a shortcut. I have it working in Windows 7 but on XP this fails.
.Net 4.0 Client Profile and Extended is installed on XP and all other parts of the applciation are functioning on XP. The project has a reference Interop.Shell32 (MIcrosoft Shell Controls and Automation through COM Interop rahter than pinvoke) and the code is simply the following:
var shl = new Shell32.Shell();
argStrLnkPath = System.IO.Path.GetFullPath(argStrLnkPath);
var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(argStrLnkPath));
var itm = dir.Items().Item(System.IO.Path.GetFileName(argStrLnkPath));
itm.Name = "My Shortcut Name";
The above works in 7 but not XP. The following versions of the Shell32.dll exist:
Win7 Shell32.dll version 6.1.7601
WinXP Shell32.dll version 6.00.29.6242
When I spy the XP shell32dll in the object browser, the same objects exist, so the functionalty should be there (unless I'm not seeing something important).
My project is set to build as x86 platform for both machines. For the reference, I have tried the Embed Interop Types as True and also copy local as False.
I have an msi installer but is there something I need to do on the target XP machine? And should I copy Local? Any ideas on the propper way to get this working?
I have run the code on that XP Machine and receive the following from teh Event Viewer:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidCastException
Embed Interop Types for Reference = True: The stackTrace for this error is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell3
2.Shell'. This operation failed because the QueryInterface call on the COM compo
nent for the interface with IID '{866738B9-6CF2-4DE8-8767-F794EBE74F4E}' failed
due to the following error: No such interface supported (Exception from HRESULT:
0x80004002 (E_NOINTERFACE)).
Embed Interop Types for Reference = False: The stackTrace for this error is:
Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException
Issue Solved! I hadn't realized that when you make those types of COM Interop inclusions, they must have a Setup Project (msi installer if going on another system). Also, another caveat is that if you have already created a setup project, you must Add > project Output again. This will automatically pull all of those interop inclusions in under the Detected Dependencies folder. This solved my issue.
I have a project that was built in Visual Studio 2005 in C#. I created an installer for the Windows application (in VS2010) and it installs and works fine on Windows XP SP3. I tried installing it on Windows 7 32-bit and it says installation is successful but when I try to open the application I receive this error message:
A fatal error has occurred. Unable to load DLL 'VistaDb20.dll': Invalid
access to memory location. (Exception from HRESULT: 0x800703E6)
People suggested I run this in the command line:
regsvr32 VistaDb20.dll
I get the error message:
The module "VistaDb20.dll" was loaded but the
entry-point DllRegisterServer was not found.
Make sure that "VistaDb20.dll" is a valid DLL or OCX
file and then try again.
So then I tried regasm VistaDb20.dll /tlb:VistaDb20.tlb using the .NET Framework Assembly Registration Utility 2.0.50727.4927 and get error:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I am not sure how to get my application running on Windows 7 with this .dll problem. Any help would be appreciated. This application and the database was created using VistaDB 2.1
I guess I can't change the actual dll since I did not create it but maybe I have to change some properties of the dll in Visual Studio?
I had this error while trying to registering my VB .NET assembly using RegAsm command:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I solved the problem buy executing RegAsm of the right .NET Framework.
I mean you should use the tools of the same Framework that you make as target in your advanced options of compilation (VS2010).
According to this your problem is that this DLL is not compatible with DEP. You'll need to disable DEP to workaround this but in the long term you should try to wean yourself off this particular dependency.
I have some old 32bit console .NET 2.0 applications that should be migrated to win2008 r2 server.
Note 1: I have one old 32bit application that doesn't load any assembly and is working correctly.
Note 2: When I start one of the applications I get
System.BadImageFormatException Could not load file or assembly error
Note 3:
Each of them are using NLog version 0.9.0.0. When I start these applications on our new server, I get following exception in nLOG.txt:
Error Could not load platform specific extensions: System.NullReferenceException: Object reference not set to an instance of an object.
at NLog.FilterFactory.AddFiltersFromAssembly(Assembly theAssembly, String prefix)
at NLog.Config.XmlLoggingConfiguration.LoadExtensionsFromAssembly(Assembly asm, String prefix)
at NLog.Config.XmlLoggingConfiguration.RegisterPlatformSpecificExtensions(String name)
Can you please help us how to solve this problem? Thank you in advance.
Deveti Putnik
Go to your project settings, and make sure you build your target to 32-bit (x86), and "All Platforms".
The problem you're seeing is a 64-bit executable trying to access a 32-bit DLL. .NET executables by default run as 64-bit on 64-bit OSes.
For point 3:Why not Upgrade NLog to 2.0, For point 2: "System.BadImageFormatException Could not load file or assembly for which assembly" can you find out assemby name causing this problem,it should be there in error message