Comments (12)
C++/.NET assemblies usually have a VTableFixups with references to methods. Executable images also have an EntryPoint.
BTW, the correct way to check for the global type is type.IsGlobalModuleType
since it doesn't have to be named <Module>
.
from dnlib.
I've tried setting the VTableFixups property to null. I've also tried to just clear the VTable property on the existing instance. Same exception.
It works if I use Write() instead of NativeWrite(), but I assume all the native stuff is gone then.
Would be helpful if the exception message showed where it was referenced.
from dnlib.
Some MD tokens are preserved when saving C++/.NET assemblies. Make sure nothing is preserved by passing in writer options that don't have those options enabled.
from dnlib.
Okay, that worked.
However, when I try to reference the written assembly in VS (Regardless of whether I use NativeWrite or Write), it displays this error.
---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'C:\Users\Morten\AppData\Local\Temp\oka2tu2gtxw05fhc\stub.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK
---------------------------
The assembly opens fine in ILSpy.
from dnlib.
Maybe VS can't handle empty assemblies? You removed every single type.
from dnlib.
I left one. But the example above was just a test.
With the actual assembly, I'm simply converting all methods to stubs.
I was attempting to port my working code from Mono.Cecil to dnlib.
from dnlib.
Cecil doesn't support mixed mode assemblies last time I checked.
If the assembly is never executed, try saving it as a non-mixed mode assembly. I have no idea why VS can't read it but ILSpy can.
from dnlib.
I tried specifying ILOnly, setting native entry point to 0 and using Write(), but VS still won't reference it. It has no problem referencing the one created by Mono.Cecil.
from dnlib.
What does peverify say?
from dnlib.
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.33440
Copyright (c) Microsoft Corporation. All rights reserved.
File not found or has bad headers.
1 Error(s) Verifying C:\Users\Morten\AppData\Local\Temp\ezqtfa5kpunsvnbe\stub.dll
from dnlib.
That error message didn't help. Who knows what it complains about. Try this and if it doesn't help, email me the file if that's possible:
mod.IsILOnly = true;
mod.VTableFixups = null;
mod.IsStrongNameSigned = false;
mod.Assembly.PublicKey = null;
mod.Assembly.HasPublicKey = false;
var opts = new ModuleWriterOptions(mod);
mod.Write("path", opts);
from dnlib.
Closed due to inactivity.
from dnlib.
Related Issues (20)
- Optimize properties on `TypeRef` and `TypeDef` HOT 3
- Import property without using typeof
- HasOverrides Generic Type HOT 2
- PDB Generated is wrong HOT 7
- Linux R2R mixed dll can't be saved. HOT 2
- Single File Executable Error: .NET data directory RVA is 0
- Potential feature: Support for 64 bit offsets and length in dnlib.IO HOT 2
- The precise method for calculating 'RVA'
- Can ITypeOrMethodDef implement IMemberDef? HOT 1
- InvalidOperationException when md rva isn't alignment HOT 5
- dnlib is missing NuGet package README file
- ModuleWriterException: Invalid section RVA HOT 1
- Should we update ReturnParameter when updating ReturnType? HOT 2
- .NET cannot install (UAC prompt when running installer)
- dnlib.DotNet.Writer.ModuleWriterException HOT 2
- "Expected a null constant." error when saving assembly with pdb HOT 6
- Why don't CreateGenericInstMethodSig HOT 25
- I already know how UnknownDeclaringType happen HOT 1
- Sort `ExportedType` table in the same way as the `TypeDef` table HOT 3
- Need to dispose of enumerators
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dnlib.