yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.55k stars 1.62k forks source link

ConfuserEx and EntityFramework EDMX generated code #196

Open milsnips opened 9 years ago

milsnips commented 9 years ago

I've got an issue where when i just build without obfuscation, my invalid database connection code returns a valid message eg. "Invalid login for user X.", but when i obfuscate the same code and try and run it to use EF to create the database, it returns me the following error:


Schema specified is not valid. Errors:

EF.EFModel.csdl(3,4) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'DataImportTrackingEntities' is already defined.

EF.EFModel.csdl(12,4) : error 0019: Each type name in a schema must be unique. Type name 'DataImportTrackingModel.MyTable1' was already defined.


Something is getting renamed or not exactly sure what, around the EF code and it causes the ef method "context.CreateDatabaseIfNotExists()" to fail with this error.

any help appreciated as to why the edmx code looks like its getting scrambled and how i can get around this problem. thanks.

xmatthias commented 9 years ago

try to open the project file (*.crproj) and modify the rule for your file as follows (attaching the argument mode...):

<rule pattern="true" inherit="false">
      <protection id="rename" >
        <argument name="mode" value="debug" />
      </protection>
    </rule>

setting the "mode" to debug is not safe - but should allow you to see where the problem comes from (as renaming is done only by attaching a _ before each function/symbol). also - the default value for "mode" is unicode which could cause exactly your problem. for production, try using "letters" or "decodable" as parameter...

source: https://github.com/yck1509/ConfuserEx/wiki/Name-Protection

yck1509 commented 9 years ago

Hi, I had not tested with Entity Framework. I'll try to look into it and see what is the problem.

milsnips commented 9 years ago

turns out, the edmx creates some metadata files which are stored as resources in dll, if you add the resource protection i think it scrambles these and the EF db connectionstring is looking for specific naming which i assume no longer exists.

ilogicsoftwares commented 7 years ago

I am having a similar error, after i protecd my wpf asembly and i run the .exe all go good but when i try to connect with user to a entityframework database i get this error "Schema specified is not valid, Each type name in schema must be unique, Type name 'MyModel.User' was already defined